Skip to content

Commit ffe1a34

Browse files
committed
feat: Enhance notes treeview loading perf - EXO-74286 - Meeds-io/meeds#2440 (#1133)
Enhance notes treeview loading perf
1 parent 13102c7 commit ffe1a34

23 files changed

+649
-526
lines changed

notes-service/src/main/java/org/exoplatform/wiki/jpa/JPADataStorage.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ public Page getParentPageOf(Page page) throws WikiException {
302302
}
303303

304304
@Override
305-
public List<Page> getChildrenPageOf(Page page, boolean withDrafts) throws WikiException {
305+
public List<Page> getChildrenPageOf(Page page, boolean withDrafts, boolean withChild) throws WikiException {
306306
PageEntity pageEntity = pageDAO.getPageOfWikiByName(page.getWikiType(), page.getWikiOwner(), page.getName());
307307
if (pageEntity == null) {
308308
throw new WikiException("Cannot get children of page " + page.getWikiType() + ":" + page.getWikiOwner() + ":"
@@ -313,7 +313,11 @@ public List<Page> getChildrenPageOf(Page page, boolean withDrafts) throws WikiEx
313313
List<PageEntity> childrenPagesEntities = pageDAO.getChildrenPages(pageEntity);
314314
if (childrenPagesEntities != null) {
315315
for (PageEntity childPageEntity : childrenPagesEntities) {
316-
childrenPages.add(convertPageEntityToPage(childPageEntity));
316+
Page childPage = convertPageEntityToPage(childPageEntity);
317+
if (withChild) {
318+
childPage.setHasChild(hasChildren(Long.parseLong(childPage.getId())));
319+
}
320+
childrenPages.add(childPage);
317321
}
318322
}
319323

@@ -1585,4 +1589,12 @@ public void deleteOrphanDraftPagesByParentPage(long parentPageId) {
15851589
public PageVersion getPageVersionById(long versionId) {
15861590
return EntityConverter.convertPageVersionEntityToPageVersion(pageVersionDAO.find(versionId));
15871591
}
1592+
1593+
/**
1594+
* {@inheritDoc}
1595+
*/
1596+
@Override
1597+
public List<DraftPage> getDraftsOfWiki(String wikiOwner, String wikiType) {
1598+
return convertDraftPageEntitiesToDraftPages(draftPageDAO.findDraftsOfWiki(wikiOwner, wikiType));
1599+
}
15881600
}

notes-service/src/main/java/org/exoplatform/wiki/jpa/dao/DraftPageDAO.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,14 @@ public Long countDraftPagesByParentPage(long parentPageId) {
116116
.setParameter("parentPageId", parentPageId)
117117
.getSingleResult();
118118
}
119+
120+
public List<DraftPageEntity> findDraftsOfWiki(String wikiOwner, String wikiType) {
121+
Query query = getEntityManager().createNativeQuery("""
122+
SELECT * FROM WIKI_DRAFT_PAGES wdp WHERE wdp.PARENT_PAGE_ID IN
123+
(SELECT wp.PAGE_ID FROM WIKI_PAGES wp INNER JOIN WIKI_WIKIS ww ON wp.WIKI_ID = ww.WIKI_ID
124+
WHERE ww.OWNER=:wikiOwner and ww.type=:wikiType)""", DraftPageEntity.class);
125+
query.setParameter("wikiOwner", wikiOwner);
126+
query.setParameter("wikiType", wikiType);
127+
return query.getResultList();
128+
}
119129
}

notes-service/src/main/java/org/exoplatform/wiki/service/DataStorage.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,12 @@ public interface DataStorage {
8080
* Get children notes and draft notes of page
8181
*
8282
* @param page the target page to retrieve its children
83-
* @param withDrafts if set to true returns the children notes and draft notes
83+
* @param withDrafts if set to true returns the children notes and draft notes,
84+
* @param withChild Check if note has child
8485
* @return children notes of page
8586
* @throws WikiException
8687
*/
87-
public List<Page> getChildrenPageOf(Page page, boolean withDrafts) throws WikiException;
88+
public List<Page> getChildrenPageOf(Page page, boolean withDrafts, boolean withChild) throws WikiException;
8889

8990
/**
9091
* Check if the given note page has children or not
@@ -317,4 +318,13 @@ public default List<Attachment> getAttachmentsOfPage(Page page, boolean loadCont
317318
* @return {@link PageVersion}
318319
*/
319320
PageVersion getPageVersionById(long versionId);
321+
322+
/**
323+
* Gets draft pages of a given wiki
324+
*
325+
* @param wikiOwner wiki owner
326+
* @param wikiType wiki type
327+
* @return {@link List} of {@link DraftPage}
328+
*/
329+
List<DraftPage> getDraftsOfWiki(String wikiOwner, String wikiType);
320330
}

notes-service/src/main/java/org/exoplatform/wiki/service/NoteService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,4 +852,13 @@ Page getNoteByIdAndLang(Long pageId, Identity userIdentity, String source, Strin
852852
* {@inheritDoc}
853853
*/
854854
DraftPage getDraftOfPageByLang(WikiPageParams param, String lang) throws WikiException;
855+
856+
/**
857+
* Gets draft pages of a given wiki
858+
*
859+
* @param wikiOwner wiki owner
860+
* @param wikiType wiki type
861+
* @return {@link List} of {@link DraftPage}
862+
*/
863+
List<DraftPage> getDraftsOfWiki(String wikiOwner, String wikiType);
855864
}

notes-service/src/main/java/org/exoplatform/wiki/service/impl/NoteServiceImpl.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -754,14 +754,7 @@ public NoteToExport getParentNoteOf(NoteToExport note) throws WikiException {
754754
*/
755755
@Override
756756
public List<Page> getChildrenNoteOf(Page note, boolean withDrafts, boolean withChild) throws WikiException {
757-
List<Page> pages = dataStorage.getChildrenPageOf(note, withDrafts);
758-
if (withChild) {
759-
for (Page page : pages) {
760-
long pageId = Long.parseLong(page.getId());
761-
page.setHasChild(hasChildren(pageId));
762-
}
763-
}
764-
return pages;
757+
return dataStorage.getChildrenPageOf(note, withDrafts, withChild);
765758
}
766759

767760
/**
@@ -1537,15 +1530,24 @@ private void deleteNoteMetadataProperties(Page note, String lang, String objectT
15371530
public void deleteVersionsByNoteIdAndLang(Long noteId, String userName, String lang) throws Exception {
15381531
deleteVersionsByNoteIdAndLang(noteId, lang);
15391532
}
1540-
1533+
1534+
/**
1535+
* {@inheritDoc}
1536+
*/
1537+
@Override
1538+
public List<DraftPage> getDraftsOfWiki(String wikiOwner, String wikiType) {
1539+
return dataStorage.getDraftsOfWiki(wikiOwner, wikiType);
1540+
}
1541+
15411542
public ExoCache<Integer, MarkupData> getRenderingCache() {
15421543
return renderingCache;
15431544
}
15441545

15451546
public Map<WikiPageParams, List<WikiPageParams>> getPageLinksMap() {
15461547
return pageLinksMap;
15471548
}
1548-
1549+
1550+
15491551
// ******* Listeners *******/
15501552

15511553
public void postUpdatePageVersionLanguage(String versionPageId) {

0 commit comments

Comments
 (0)