|
|
@@ -344,7 +344,7 @@ class ElasticsearchDelegator {
|
|
|
|
|
|
addAllPages() {
|
|
|
const Page = mongoose.model('Page');
|
|
|
- return this.updateOrInsertPages(() => Page.find(), true);
|
|
|
+ return this.updateOrInsertPages(() => Page.find(), { isEmittingProgressEvent: true, fireGarbageCollection: true });
|
|
|
}
|
|
|
|
|
|
updateOrInsertPageById(pageId) {
|
|
|
@@ -355,7 +355,9 @@ class ElasticsearchDelegator {
|
|
|
/**
|
|
|
* @param {function} queryFactory factory method to generate a Mongoose Query instance
|
|
|
*/
|
|
|
- async updateOrInsertPages(queryFactory, isEmittingProgressEvent = false) {
|
|
|
+ async updateOrInsertPages(queryFactory, option = {}) {
|
|
|
+ const { isEmittingProgressEvent = false, fireGarbageCollection = false } = option;
|
|
|
+
|
|
|
const Page = mongoose.model('Page');
|
|
|
const { PageQueryBuilder } = Page;
|
|
|
const Bookmark = mongoose.model('Bookmark');
|
|
|
@@ -465,12 +467,14 @@ class ElasticsearchDelegator {
|
|
|
logger.error('addAllPages error on add anyway: ', err);
|
|
|
}
|
|
|
|
|
|
- try {
|
|
|
- // First aid to prevent unexplained memory leaks
|
|
|
- global.gc();
|
|
|
- }
|
|
|
- catch (err) {
|
|
|
- logger.error('fail garbage collection: ', err);
|
|
|
+ if (fireGarbageCollection) {
|
|
|
+ try {
|
|
|
+ // First aid to prevent unexplained memory leaks
|
|
|
+ global.gc();
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ logger.error('fail garbage collection: ', err);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
callback();
|