@@ -109,10 +109,9 @@ class Pages {
109109 public static async getParentSelectOptions (
110110 excludePageId ?: EntityId
111111 ) : Promise < Array < { page : Page ; depth : number ; indent : string } > > {
112- const pages = excludePageId
113- ? await this . groupByParent ( excludePageId )
114- : await this . groupByParent ( ) ;
115- const pagesMap = await this . getPagesMap ( ) ;
112+ const { pages, pagesMap } = excludePageId
113+ ? await this . groupByParentWithMap ( excludePageId )
114+ : await this . groupByParentWithMap ( '' as EntityId ) ;
116115 const indentUnit = '\u00a0\u00a0' ;
117116
118117 return pages . map ( ( page ) => {
@@ -123,21 +122,20 @@ class Pages {
123122 }
124123
125124 /**
126- * Group all pages by their parents
127- * If the pageId is passed, it excludes passed page from result pages
128- *
129- * @param {string } pageId - pageId to exclude from result pages
130- * @returns {Page[] }
125+ * Same as {@link groupByParent} but returns the pages map from the same load (no second getPagesMap).
131126 */
132- public static async groupByParent ( pageId = '' as EntityId ) : Promise < Page [ ] > {
127+ private static async groupByParentWithMap ( pageId = '' as EntityId ) : Promise < {
128+ pages : Page [ ] ;
129+ pagesMap : Map < string , Page > ;
130+ } > {
133131 const rootPageOrder = await PagesOrder . getRootPageOrder ( ) ; // get order of the root pages
134132 const childPageOrder = await PagesOrder . getChildPageOrder ( ) ; // get order of the all other pages
135133
136134 /**
137135 * If there is no root and child page order, then it returns an empty array
138136 */
139137 if ( ! rootPageOrder || ( ! rootPageOrder && childPageOrder . length <= 0 ) ) {
140- return [ ] ;
138+ return { pages : [ ] , pagesMap : new Map ( ) } ;
141139 }
142140
143141 const pagesMap = await this . getPagesMap ( ) ;
@@ -176,16 +174,31 @@ class Pages {
176174 * Otherwise just returns result itself
177175 */
178176 if ( pageId ) {
179- return this . removeChildren ( result , pageId ) . reduce ( ( prev , curr ) => {
177+ const pages = this . removeChildren ( result , pageId ) . reduce ( ( prev , curr ) => {
180178 if ( curr instanceof Page ) {
181179 prev . push ( curr ) ;
182180 }
183181
184182 return prev ;
185183 } , Array < Page > ( ) ) ;
186- } else {
187- return result ;
184+
185+ return { pages , pagesMap } ;
188186 }
187+
188+ return { pages : result , pagesMap } ;
189+ }
190+
191+ /**
192+ * Group all pages by their parents
193+ * If the pageId is passed, it excludes passed page from result pages
194+ *
195+ * @param {string } pageId - pageId to exclude from result pages
196+ * @returns {Page[] }
197+ */
198+ public static async groupByParent ( pageId = '' as EntityId ) : Promise < Page [ ] > {
199+ const { pages } = await this . groupByParentWithMap ( pageId ) ;
200+
201+ return pages ;
189202 }
190203
191204 /**
0 commit comments