Skip to content

Commit

Permalink
fix: Treeview menu loading perf issue- EXO-73169 - Meeds-io/MIPs#129 (#…
Browse files Browse the repository at this point in the history
…1115)

Treeview menu loading perf issue

fix: Treeview menu loading perf issue- EXO-73169 - Meeds-io/MIPs#129
  • Loading branch information
hakermi committed Sep 20, 2024
1 parent 08805fe commit 71c99ca
Show file tree
Hide file tree
Showing 18 changed files with 230 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,15 @@ public List<Page> getChildrenPageOf(Page page, boolean withDrafts) throws WikiEx
}

@Override
public boolean hasChildren(long noteId) throws WikiException {
public boolean hasChildren(long noteId) {
return pageDAO.countPageChildrenById(noteId) > 0;
}

@Override
public boolean hasDrafts(long noteId) {
return draftPageDAO.countDraftPagesByParentPage(noteId) > 0;
}

@Override
@ExoTransactional
public void deletePage(String wikiType, String wikiOwner, String pageName) throws WikiException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,9 @@ public DraftPageEntity findLatestDraftPageByTargetPageAndLang(Long targetPageId,
}
}

public Long countDraftPagesByParentPage(long parentPageId) {
return (Long) getEntityManager().createNamedQuery("wikiDraftPage.countDraftPagesByParentPage")
.setParameter("parentPageId", parentPageId)
.getSingleResult();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
@NamedQuery(name = "wikiDraftPage.findLatestDraftPageByTargetPage", query = "SELECT d FROM WikiDraftPageEntity d WHERE d.targetPage.id = :targetPageId ORDER BY d.updatedDate DESC"),
@NamedQuery(name = "wikiDraftPage.findDraftPageByTargetPage", query = "SELECT d FROM WikiDraftPageEntity d WHERE d.targetPage.id = :targetPageId"),
@NamedQuery(name = "wikiDraftPage.findDraftPagesByParentPage", query = "SELECT d FROM WikiDraftPageEntity d WHERE d.parentPage.id = :parentPageId"),
@NamedQuery(name = "wikiDraftPage.countDraftPagesByParentPage", query = "SELECT count(*) FROM WikiDraftPageEntity d WHERE d.parentPage.id = :parentPageId"),
@NamedQuery(name = "wikiDraftPage.findLatestDraftPageByTargetPageAndLang", query = "SELECT d FROM WikiDraftPageEntity d WHERE d.targetPage.id = :targetPageId AND " +
"((:lang IS NULL AND d.lang IS NULL) OR (:lang IS NOT NULL AND d.lang = :lang)) ORDER BY d.updatedDate DESC"),
@NamedQuery(name = "wikiDraftPage.deleteOrphanDraftPagesByParentPage", query = "DELETE FROM WikiDraftPageEntity d WHERE d.targetPage IS NULL AND d.parentPage.id=:id")})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
@NamedQuery(name = "wikiPage.getPagesOfWiki", query = "SELECT p FROM WikiPageEntity p JOIN p.wiki w WHERE w.type = :type AND w.owner = :owner AND p.deleted = :deleted"),
@NamedQuery(name = "wikiPage.getChildrenPages", query = "SELECT p FROM WikiPageEntity p WHERE p.parentPage.id = :id AND p.deleted = false ORDER BY p.name"),
@NamedQuery(name = "wikiPage.getAllPagesBySyntax", query = "SELECT p FROM WikiPageEntity p WHERE p.syntax = :syntax OR p.syntax IS NULL ORDER BY p.updatedDate DESC"),
@NamedQuery(name = "wikiPage.countPageChildrenById", query = "SELECT COUNT(*) FROM WikiPageEntity p WHERE p.parentPage.id = :id"),
@NamedQuery(name = "wikiPage.countPageChildrenById", query = "SELECT COUNT(*) FROM WikiPageEntity p WHERE p.parentPage.id = :id AND p.deleted = false"),
})
public class PageEntity extends BasePageEntity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,21 @@ public interface DataStorage {
*/
public List<Page> getChildrenPageOf(Page page, boolean withDrafts) throws WikiException;

public boolean hasChildren(long noteId) throws WikiException;
/**
* Check if the given note page has children or not
*
* @param noteId note page id
* @return true if the given note page has children and false if not
*/
public boolean hasChildren(long noteId);

/**
* Check if the given note page has drafts or not
*
* @param noteId note page id
* @return true if the given note page has drafts and false if not
*/
boolean hasDrafts(long noteId);

public void deletePage(String wikiType, String wikiOwner, String pageId) throws WikiException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,22 @@ Page getNoteOfNoteBookByName(String noteType,
*/
List<Page> getChildrenNoteOf(Page note, boolean withDrafts, boolean withChild) throws WikiException;

/**
* Check if the given note page has children or not
*
* @param pageId note page id
* @return true if the given note page has children and false if not
*/
boolean hasChildren(long pageId);

/**
* Check if the given note page has drafts or not
*
* @param pageId note page id
* @return true if the given note page has drafts and false if not
*/
boolean hasDrafts(long pageId);

/**
* Get all the children notes of a note
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,12 +672,28 @@ public List<Page> getChildrenNoteOf(Page note, boolean withDrafts, boolean withC
if (withChild) {
for (Page page : pages) {
long pageId = Long.parseLong(page.getId());
page.setHasChild(dataStorage.hasChildren(pageId));
page.setHasChild(hasChildren(pageId));
}
}
return pages;
}


/**
* {@inheritDoc}
*/
@Override
public boolean hasChildren(long pageId) {
return dataStorage.hasChildren(pageId);
}

/**
* {@inheritDoc}
*/
@Override
public boolean hasDrafts(long pageId) {
return dataStorage.hasDrafts(pageId);
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Optional;
import java.util.ResourceBundle;
import java.util.Set;
Expand All @@ -45,7 +46,9 @@
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.CacheControl;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.EntityTag;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;

Expand Down Expand Up @@ -1226,12 +1229,13 @@ public Response getFullTreeData(@Parameter(description = "Note path", required =

List<JsonNodeData> finalTree = new ArrayList<>();
responseData = getJsonTree(noteParam, context);
JsonNodeData rootNodeData = responseData.get(0);
JsonNodeData rootNodeData = responseData.getFirst();
rootNodeData.setHasDraftDescendant(true);
finalTree.add(rootNodeData);
context.put(TreeNode.DEPTH, "1");

List<JsonNodeData> children = new ArrayList<>(rootNodeData.getChildren());
List<JsonNodeData> listChildren = rootNodeData.getChildren();
List<JsonNodeData> children = listChildren != null ? new ArrayList<>(listChildren) : new ArrayList<>();
List<JsonNodeData> parents = new ArrayList<>();

do {
Expand Down Expand Up @@ -1299,7 +1303,7 @@ public Response getFullTreeData(@Parameter(description = "Note path", required =
|| Boolean.TRUE.equals(jsonNodeData.isHasDraftDescendant()))
.collect(Collectors.toList());
}
while (bottomChildren.size() > 1 || (bottomChildren.size() == 1 && bottomChildren.get(0).getParentPageId() != null)) {
while (bottomChildren.size() > 1 || (bottomChildren.size() == 1 && bottomChildren.getFirst().getParentPageId() != null)) {
for (JsonNodeData bottomChild : bottomChildren) {
String parentPageId = bottomChild.getParentPageId();
Optional<JsonNodeData> parentOptional = finalTree.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,13 @@ public JsonNodeData(TreeNode treeNode,
this.children = TreeUtils.tranformToJson(treeNode, context);
this.isSelected = treeNode.isSelected();
this.isRestricted = treeNode.isRetricted;
if (!this.children.isEmpty()) {
if (this.children != null && !this.children.isEmpty()) {
this.isExpanded = true;
}
if (treeNode.getNodeType().equals(TreeNodeType.PAGE)) {
Page page = ((PageTreeNode) treeNode).getPage();
this.isDraftPage = page.isDraftPage();
this.parentPageId = page.getParentPageId();
this.lang = page.getLang();
this.url = page.getUrl();
this.lang = page.getLang();
boolean withDrafts = context.containsKey(TreeNode.WITH_DRAFTS) && (boolean) context.get(TreeNode.WITH_DRAFTS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.util.HashMap;
import java.util.Iterator;

import lombok.Getter;
import lombok.Setter;
import org.exoplatform.container.ExoContainerContext;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
Expand All @@ -39,6 +41,8 @@
public class PageTreeNode extends TreeNode {
private static final Log log = ExoLogger.getLogger(PageTreeNode.class);

@Setter
@Getter
private Page page;

private NoteService noteService;
Expand All @@ -55,15 +59,8 @@ public PageTreeNode(Page page) throws Exception {
this.page = page;
this.id = page.getId();
this.path = buildPath();
this.hasChild = !page.isDraftPage() && !noteService.getChildrenNoteOf(page, true, false).isEmpty();
}

public Page getPage() {
return page;
}

public void setPage(Page page) {
this.page = page;
this.hasChild = !page.isDraftPage() && (noteService.hasChildren(Long.parseLong(page.getId()))
|| noteService.hasDrafts(Long.parseLong(page.getId())));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public WikiHomeTreeNode(Page wikiHome) throws Exception {

this.wikiHome = wikiHome;
this.path = this.buildPath();
this.hasChild = !wikiHome.isDraftPage() && !noteService.getChildrenNoteOf(wikiHome, true, true).isEmpty();
this.hasChild = !wikiHome.isDraftPage() && (noteService.hasChildren(Long.parseLong(wikiHome.getId()))
|| noteService.hasDrafts(Long.parseLong(wikiHome.getId())));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,27 +100,25 @@ public static List<JsonNodeData> tranformToJson(TreeNode treeNode, HashMap<Strin
canEdit = (Boolean)context.get(TreeNode.CAN_EDIT);
}

List<JsonNodeData> children = new ArrayList<JsonNodeData>();
List<JsonNodeData> children = new ArrayList<>();
for (TreeNode child : treeNode.getChildren()) {
boolean isSelectable = true;
boolean isLastNode = false;
if (counter >= treeNode.getChildren().size()) {
isLastNode = true;
}

boolean isLastNode = counter >= treeNode.getChildren().size();

if (child.getNodeType().equals(TreeNodeType.WIKI)) {
isSelectable = false;
} else if (child.getNodeType().equals(TreeNodeType.PAGE)) {
Page page = ((PageTreeNode) child).getPage();
if (((currentPage != null) && (currentPage.equals(page) || Utils.isDescendantPage(page, currentPage)))) {
isSelectable = false;
}

if (!noteService.hasPermissionOnPage(page, PermissionType.VIEWPAGE, ConversationState.getCurrent().getIdentity())) {
isSelectable = false;
child.setRetricted(true);
}
if(BooleanUtils.isTrue(canEdit) && !noteService.hasPermissionOnPage(page, PermissionType.EDITPAGE, ConversationState.getCurrent().getIdentity())){
if (BooleanUtils.isTrue(canEdit)
&& !noteService.hasPermissionOnPage(page, PermissionType.EDITPAGE, ConversationState.getCurrent().getIdentity())) {
isSelectable = false;
child.setRetricted(true);
}
Expand All @@ -131,21 +129,22 @@ public static List<JsonNodeData> tranformToJson(TreeNode treeNode, HashMap<Strin
child.setRetricted(true);
}

if(BooleanUtils.isTrue(canEdit) && !noteService.hasPermissionOnPage(page, PermissionType.EDITPAGE, ConversationState.getCurrent().getIdentity())){
if (BooleanUtils.isTrue(canEdit)
&& !noteService.hasPermissionOnPage(page, PermissionType.EDITPAGE, ConversationState.getCurrent().getIdentity())) {
isSelectable = false;
child.setRetricted(true);
}

}

String excerpt = null;
if (showExcerpt != null && showExcerpt) {
WikiPageParams params = getPageParamsFromPath(child.getPath());
// FIXME Migration - Remove excerpt support ?
//excerpt = ExcerptUtils.getExcerpts(params);
// excerpt = ExcerptUtils.getExcerpts(params);
excerpt = "";
}

children.add(new JsonNodeData(child, isLastNode, isSelectable, currentPath, excerpt, context));
counter++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.when;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Deque;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -332,6 +334,7 @@ public void testGetFullTreeData() throws Exception {

when(noteBookService.getWikiByTypeAndOwner(pageParams.getType(), pageParams.getOwner())).thenReturn(noteBook);
when(noteBookService.getWikiByTypeAndOwner(homePage.getWikiType(), homePage.getWikiOwner())).thenReturn(noteBook);
when(noteService.hasChildren(Long.parseLong(homePage.getId()))).thenReturn(true);
when(noteService.getChildrenNoteOf(homePage, true, false)).thenReturn(childrenWithDraft);
when(noteService.getChildrenNoteOf(homePage, false, false)).thenReturn(childrenWithoutDrafts);

Expand Down
18 changes: 17 additions & 1 deletion notes-webapp/src/main/webapp/javascript/eXo/wiki/notesService.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ export function getSeparator(url) {
}

export function getNoteTree(noteBookType, noteBookOwner, noteId,treeType) {
return fetch(`${notesConstants.PORTAL}/${notesConstants.PORTAL_REST}/notes/tree/${treeType}?path=${noteBookType}/${noteBookOwner}/${noteId}`, {
if (noteBookOwner.indexOf('/') !== 0) {
noteBookOwner = `/${noteBookOwner}`;
}
return fetch(`${notesConstants.PORTAL}/${notesConstants.PORTAL_REST}/notes/tree/${treeType}?path=${noteBookType}${noteBookOwner}/${noteId}`, {
method: 'GET',
credentials: 'include',
}).then(resp => {
Expand All @@ -96,6 +99,19 @@ export function getNoteTree(noteBookType, noteBookOwner, noteId,treeType) {
});
}

export function getNoteTreeLevel(path) {
return fetch(`${notesConstants.PORTAL}/${notesConstants.PORTAL_REST}/notes/tree/children?path=${path}`, {
method: 'GET',
credentials: 'include',
}).then(resp => {
if (!resp || !resp.ok) {
throw new Error('Error while getting note tree level');
} else {
return resp.json();
}
});
}

export function getFullNoteTree(noteBookType, noteBookOwner, noteId, withDrafts, lang) {
if (noteBookOwner.indexOf('/') !== 0) {
noteBookOwner = `/${noteBookOwner}`;
Expand Down
25 changes: 18 additions & 7 deletions notes-webapp/src/main/webapp/skin/less/notes/notes.less
Original file line number Diff line number Diff line change
Expand Up @@ -1156,11 +1156,22 @@ ul.note-manual-child {
opacity: 0 !important;
}

.remove-focus:focus::after {
opacity: 0 !important;
}




.notes-custom-treeview {
> .v-treeview-node {
> .v-treeview-node__root {
.v-treeview-node__toggle,
> .v-treeview-node__level:first-child {
display: none;
}
}
}

> .v-treeview-node__children {
> .v-treeview-node__root {
.v-treeview-node__toggle,
> .v-treeview-node__level:nth-child(2) {
display: none;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ export default {
}
}
};
</script>
</script>
Loading

0 comments on commit 71c99ca

Please sign in to comment.