File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -139,7 +139,11 @@ async function run() {
139
139
140
140
const contents = generateContents ( ) ;
141
141
142
- let count = 0 ;
142
+ const promises = [ ] ;
143
+ let lastPrint = 0 ;
144
+
145
+ let doneCount = 0 ;
146
+ console . log ( 'Search Content to save:' , contents . length ) ;
143
147
for ( const content of contents ) {
144
148
if ( version === '8.x' ) {
145
149
let url = content . url . startsWith ( '/' ) ? content . url : `/${ content . url } ` ;
@@ -154,18 +158,28 @@ async function run() {
154
158
}
155
159
content . url = `/docs/${ version } ${ url } ` ;
156
160
}
157
- console . log ( `${ ++ count } / ${ contents . length } ` ) ;
158
- await content . save ( ) ;
161
+ const promise = content . save ( ) . then ( ( ) => {
162
+ doneCount += 1 ;
163
+ const nowDate = Date . now ( ) ;
164
+ // only print every 2 seconds, or if it is the first or last element
165
+ if ( nowDate - lastPrint > 2000 || doneCount === contents . length || doneCount === 1 ) {
166
+ lastPrint = nowDate ;
167
+ console . log ( `${ doneCount } / ${ contents . length } ` ) ;
168
+ }
169
+ } ) ;
170
+ promises . push ( promise ) ;
159
171
}
160
172
173
+ await Promise . allSettled ( promises ) ;
174
+
161
175
const results = await Content .
162
176
find ( { $text : { $search : 'validate' } , version } , { score : { $meta : 'textScore' } } ) .
163
177
sort ( { score : { $meta : 'textScore' } } ) .
164
178
limit ( 10 ) ;
165
179
166
180
console . log ( results . map ( res => res . url ) ) ;
167
181
168
- console . log ( `Added ${ contents . length } Content` ) ;
182
+ console . log ( `Added ${ contents . length } Search Content` ) ;
169
183
170
184
process . exit ( 0 ) ;
171
185
}
You can’t perform that action at this time.
0 commit comments