Skip to content

Commit

Permalink
feat: Enhance notes treeview loading perf - EXO-74286 - Meeds-io/MIPs…
Browse files Browse the repository at this point in the history
…#129

Enhance notes treeviel loading perf
  • Loading branch information
hakermi committed Sep 25, 2024
1 parent 4d423e3 commit 01f363d
Show file tree
Hide file tree
Showing 23 changed files with 629 additions and 528 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public Page getParentPageOf(Page page) throws WikiException {
}

@Override
public List<Page> getChildrenPageOf(Page page, boolean withDrafts) throws WikiException {
public List<Page> getChildrenPageOf(Page page, boolean withDrafts, boolean withChild) throws WikiException {
PageEntity pageEntity = pageDAO.getPageOfWikiByName(page.getWikiType(), page.getWikiOwner(), page.getName());
if (pageEntity == null) {
throw new WikiException("Cannot get children of page " + page.getWikiType() + ":" + page.getWikiOwner() + ":"
Expand All @@ -313,7 +313,11 @@ public List<Page> getChildrenPageOf(Page page, boolean withDrafts) throws WikiEx
List<PageEntity> childrenPagesEntities = pageDAO.getChildrenPages(pageEntity);
if (childrenPagesEntities != null) {
for (PageEntity childPageEntity : childrenPagesEntities) {
childrenPages.add(convertPageEntityToPage(childPageEntity));
Page childPage = convertPageEntityToPage(childPageEntity);
if (withChild) {
childPage.setHasChild(hasChildren(Long.parseLong(childPage.getId())));
}
childrenPages.add(childPage);
}
}

Expand Down Expand Up @@ -1586,4 +1590,12 @@ public void deleteOrphanDraftPagesByParentPage(long parentPageId) {
public PageVersion getPageVersionById(long versionId) {
return EntityConverter.convertPageVersionEntityToPageVersion(pageVersionDAO.find(versionId));
}

/**
* {@inheritDoc}
*/
@Override
public List<DraftPage> getDraftsOfWiki(String wikiOwner, String wikiType) {
return convertDraftPageEntitiesToDraftPages(draftPageDAO.findDraftsOfWiki(wikiOwner, wikiType));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,14 @@ public Long countDraftPagesByParentPage(long parentPageId) {
.setParameter("parentPageId", parentPageId)
.getSingleResult();
}

public List<DraftPageEntity> findDraftsOfWiki(String wikiOwner, String wikiType) {
Query query = getEntityManager().createNativeQuery("""
SELECT * FROM WIKI_DRAFT_PAGES wdp WHERE wdp.PARENT_PAGE_ID IN
(SELECT wp.PAGE_ID FROM WIKI_PAGES wp INNER JOIN WIKI_WIKIS ww ON wp.WIKI_ID = ww.WIKI_ID
WHERE ww.OWNER=:wikiOwner and ww.type=:wikiType)""", DraftPageEntity.class);
query.setParameter("wikiOwner", wikiOwner);
query.setParameter("wikiType", wikiType);
return query.getResultList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ public interface DataStorage {
* Get children notes and draft notes of page
*
* @param page the target page to retrieve its children
* @param withDrafts if set to true returns the children notes and draft notes
* @param withDrafts if set to true returns the children notes and draft notes,
* @param withChild Check if note has child
* @return children notes of page
* @throws WikiException
*/
public List<Page> getChildrenPageOf(Page page, boolean withDrafts) throws WikiException;
public List<Page> getChildrenPageOf(Page page, boolean withDrafts, boolean withChild) throws WikiException;

/**
* Check if the given note page has children or not
Expand Down Expand Up @@ -317,4 +318,13 @@ public default List<Attachment> getAttachmentsOfPage(Page page, boolean loadCont
* @return {@link PageVersion}
*/
PageVersion getPageVersionById(long versionId);

/**
* Gets draft pages of a given wiki
*
* @param wikiOwner wiki owner
* @param wikiType wiki type
* @return {@link List} of {@link DraftPage}
*/
List<DraftPage> getDraftsOfWiki(String wikiOwner, String wikiType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -851,4 +851,13 @@ Page getNoteByIdAndLang(Long pageId, Identity userIdentity, String source, Strin
* {@inheritDoc}
*/
DraftPage getDraftOfPageByLang(WikiPageParams param, String lang) throws WikiException;

/**
* Gets draft pages of a given wiki
*
* @param wikiOwner wiki owner
* @param wikiType wiki type
* @return {@link List} of {@link DraftPage}
*/
List<DraftPage> getDraftsOfWiki(String wikiOwner, String wikiType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -757,14 +757,7 @@ public NoteToExport getParentNoteOf(NoteToExport note) throws WikiException {
*/
@Override
public List<Page> getChildrenNoteOf(Page note, boolean withDrafts, boolean withChild) throws WikiException {
List<Page> pages = dataStorage.getChildrenPageOf(note, withDrafts);
if (withChild) {
for (Page page : pages) {
long pageId = Long.parseLong(page.getId());
page.setHasChild(hasChildren(pageId));
}
}
return pages;
return dataStorage.getChildrenPageOf(note, withDrafts, withChild);
}

/**
Expand Down Expand Up @@ -1742,6 +1735,14 @@ public PageVersion getPageVersionById(Long versionId) {
return dataStorage.getPageVersionById(versionId);
}

/**
* {@inheritDoc}
*/
@Override
public List<DraftPage> getDraftsOfWiki(String wikiOwner, String wikiType) {
return dataStorage.getDraftsOfWiki(wikiOwner, wikiType);
}

// ******* Listeners *******/

public void postUpdatePageVersionLanguage(String versionPageId) {
Expand Down
Loading

0 comments on commit 01f363d

Please sign in to comment.