Skip to content

Commit 05e9d15

Browse files
committed
feat: Enhance notes treeview loading perf - EXO-74286 - Meeds-io/MIPs#129 (#1132)
Enhance notes treeview loading perf
1 parent 0a3e336 commit 05e9d15

23 files changed

+630
-528
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

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

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
@@ -851,4 +851,13 @@ Page getNoteByIdAndLang(Long pageId, Identity userIdentity, String source, Strin
851851
* {@inheritDoc}
852852
*/
853853
DraftPage getDraftOfPageByLang(WikiPageParams param, String lang) throws WikiException;
854+
855+
/**
856+
* Gets draft pages of a given wiki
857+
*
858+
* @param wikiOwner wiki owner
859+
* @param wikiType wiki type
860+
* @return {@link List} of {@link DraftPage}
861+
*/
862+
List<DraftPage> getDraftsOfWiki(String wikiOwner, String wikiType);
854863
}

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -757,14 +757,7 @@ public NoteToExport getParentNoteOf(NoteToExport note) throws WikiException {
757757
*/
758758
@Override
759759
public List<Page> getChildrenNoteOf(Page note, boolean withDrafts, boolean withChild) throws WikiException {
760-
List<Page> pages = dataStorage.getChildrenPageOf(note, withDrafts);
761-
if (withChild) {
762-
for (Page page : pages) {
763-
long pageId = Long.parseLong(page.getId());
764-
page.setHasChild(hasChildren(pageId));
765-
}
766-
}
767-
return pages;
760+
return dataStorage.getChildrenPageOf(note, withDrafts, withChild);
768761
}
769762

770763
/**
@@ -1742,6 +1735,14 @@ public PageVersion getPageVersionById(Long versionId) {
17421735
return dataStorage.getPageVersionById(versionId);
17431736
}
17441737

1738+
/**
1739+
* {@inheritDoc}
1740+
*/
1741+
@Override
1742+
public List<DraftPage> getDraftsOfWiki(String wikiOwner, String wikiType) {
1743+
return dataStorage.getDraftsOfWiki(wikiOwner, wikiType);
1744+
}
1745+
17451746
// ******* Listeners *******/
17461747

17471748
public void postUpdatePageVersionLanguage(String versionPageId) {

0 commit comments

Comments
 (0)