Skip to content

Commit

Permalink
fix: Treeview menu loading perf issue - EXO-73169 - Meeds-io/meeds#2411
Browse files Browse the repository at this point in the history
Resolves Meeds-io/meeds#2411

(cherry picked from commit 9c6d075)
  • Loading branch information
Jihed525 committed Sep 27, 2024
1 parent febc5ef commit 59b1b64
Show file tree
Hide file tree
Showing 18 changed files with 214 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,15 @@ public List<Page> getChildrenPageOf(Page page, String userId, boolean withDrafts
}

@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 @@ -116,4 +116,9 @@ public DraftPageEntity findLatestDraftPageByUserAndTargetPageAndLang(Long target
}
}

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 @@ -31,6 +31,7 @@
@ExoEntity
@Table(name = "WIKI_DRAFT_PAGES")
@NamedQueries({
@NamedQuery(name = "wikiDraftPage.countDraftPagesByParentPage", query = "SELECT count(*) FROM WikiDraftPageEntity d WHERE d.parentPage.id = :parentPageId"),
@NamedQuery(name = "wikiDraftPage.findDraftPagesByUser", query = "SELECT d FROM WikiDraftPageEntity d WHERE d.author = :username ORDER BY d.updatedDate DESC"),
@NamedQuery(name = "wikiDraftPage.findDraftPageByUserAndName", query = "SELECT d FROM WikiDraftPageEntity d WHERE d.author = :username AND d.name = :draftPageName ORDER BY d.updatedDate DESC"),
@NamedQuery(name = "wikiDraftPage.findLatestDraftPageByUserAndTargetPage", query = "SELECT d FROM WikiDraftPageEntity d WHERE d.author = :username AND d.targetPage.id = :targetPageId ORDER BY d.updatedDate DESC"),
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 @@ -77,7 +77,21 @@ public interface DataStorage {
*/
public List<Page> getChildrenPageOf(Page page, String userId, 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 @@ -191,6 +191,22 @@ Page getNoteOfNoteBookByName(String noteType,
*/
Page getParentNoteOf(Page note) 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 @@ -624,12 +624,31 @@ public List<Page> getChildrenNoteOf(Page note, String userId, boolean withDrafts
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}
*/
@Override
public List<NoteToExport> getChildrenNoteOf(NoteToExport note, String userId) throws WikiException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,8 @@ public Response getFullTreeData(@Parameter(description = "Note path", required =
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
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ 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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
*/
package org.exoplatform.wiki.tree;

import java.util.Collection;
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 @@ -36,6 +42,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 @@ -48,15 +56,8 @@ public PageTreeNode(Page page) throws Exception {
this.page = page;
this.id = page.getId();
this.path = buildPath();
this.hasChild = !page.isDraftPage() && !noteService.getChildrenNoteOf(page, ConversationState.getCurrent().getIdentity().getUserId(), 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 @@ -55,7 +55,8 @@ public WikiHomeTreeNode(Page wikiHome) throws Exception {

this.wikiHome = wikiHome;
this.path = this.buildPath();
this.hasChild = !wikiHome.isDraftPage() && !noteService.getChildrenNoteOf(wikiHome, ConversationState.getCurrent().getIdentity().getUserId(), 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 @@ -268,14 +268,9 @@ public void getFullTreeData() throws Exception {

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

treeUtilsStatic.when(() -> TreeUtils.getPathFromPageParams(any())).thenCallRealMethod();
treeUtilsStatic.when(() -> TreeUtils.tranformToJson(any(), any())).thenCallRealMethod();
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 @@ -1144,11 +1144,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>
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,11 @@ export default {
});
}
},
fetchChildren(note) {
return this.$notesService.getNoteTreeLevel(note.path, this.selectedTranslation?.value).then(data => {
note.children = data?.jsonList;
});
},
retrieveNoteTree(noteType, noteOwner, noteName) {
const withDrafts = this.filter === this.$t('notes.filter.label.drafts');
this.$notesService.getFullNoteTree(noteType, noteOwner , noteName, withDrafts, this.selectedTranslation).then(data => {
Expand Down
Loading

0 comments on commit 59b1b64

Please sign in to comment.