@@ -40,17 +40,21 @@ export interface AppState {
4040 isServerDown : boolean
4141 isStartedFetching : boolean
4242 isPreparingIndexing : boolean
43+ isIndexing : boolean
4344 didPassDiscord : boolean
4445 discordCodeInput : string
4546 docsLeftToIndex : number
4647 docsInIndexing : number
47- lastServerDownTimestamp : number
48+ docsIndexed : number
49+ timeSinceLastIndexing : number
50+ serverDownCount : number
4851 showResultsPage : boolean
4952}
5053
5154export interface ServerStatus {
5255 docs_in_indexing : number
5356 docs_left_to_index : number
57+ docs_indexed : number
5458}
5559
5660Modal . setAppElement ( '#root' ) ;
@@ -103,8 +107,11 @@ export default class App extends React.Component <{}, AppState>{
103107 didPassDiscord : false ,
104108 docsLeftToIndex : 0 ,
105109 docsInIndexing : 0 ,
110+ docsIndexed : 0 ,
111+ isIndexing : false ,
112+ serverDownCount : 0 ,
113+ timeSinceLastIndexing : 0 ,
106114 searchDuration : 0 ,
107- lastServerDownTimestamp : 0 ,
108115 showResultsPage : false
109116 }
110117
@@ -164,11 +171,9 @@ export default class App extends React.Component <{}, AppState>{
164171 }
165172
166173 async fetchStatsusForever ( ) {
167- let successSleepSeconds = 1 ;
168174 let timeBetweenFailToast = 5 ;
169175 let failSleepSeconds = 1 ;
170-
171- api . get < ServerStatus > ( '/status' ) . then ( ( res ) => {
176+ api . get < ServerStatus > ( '/status' , { timeout : 3000 } ) . then ( ( res ) => {
172177 if ( this . state . isServerDown ) {
173178 toast . dismiss ( ) ;
174179 if ( ! document . hidden ) {
@@ -178,33 +183,37 @@ export default class App extends React.Component <{}, AppState>{
178183 }
179184
180185 let isPreparingIndexing = this . state . isPreparingIndexing ;
181- if ( this . state . isPreparingIndexing && ( res . data . docs_in_indexing > 0 || res . data . docs_left_to_index > 0 ) ) {
186+ let isIndexing = this . state . isIndexing ;
187+ let lastIndexingTime = this . state . timeSinceLastIndexing ;
188+ if ( res . data . docs_in_indexing > 0 || res . data . docs_left_to_index > 0 || ( res . data . docs_indexed > this . state . docsIndexed && this . state . docsIndexed > 0 ) ) {
189+ isIndexing = true ;
190+ lastIndexingTime = Date . now ( ) ;
182191 isPreparingIndexing = false ;
183- }
184-
185- if ( this . state . docsInIndexing > 0 && ( res . data . docs_in_indexing === 0 && res . data . docs_left_to_index === 0 ) ) {
192+ } else if ( isIndexing && Date . now ( ) - lastIndexingTime > ( 1000 * 60 * 1 ) ) {
193+ isIndexing = false ;
186194 toast . success ( "Indexing finished." , { autoClose : 2000 } ) ;
187195 }
188196
189197 this . setState ( { isServerDown : false , docsLeftToIndex : res . data . docs_left_to_index ,
190- docsInIndexing : res . data . docs_in_indexing , isPreparingIndexing : isPreparingIndexing } ) ;
198+ docsInIndexing : res . data . docs_in_indexing , isPreparingIndexing : isPreparingIndexing ,
199+ docsIndexed : res . data . docs_indexed , isIndexing : isIndexing , timeSinceLastIndexing : lastIndexingTime } ) ;
191200
192- let timeToSleep = isPreparingIndexing ? 1000 : successSleepSeconds * 1000 ;
201+ let timeToSleep = 1000 ;
193202 setTimeout ( ( ) => this . fetchStatsusForever ( ) , timeToSleep ) ;
194203 } ) . catch ( ( err ) => {
195- this . setState ( { isServerDown : true } ) ;
204+ this . setState ( { serverDownCount : this . state . serverDownCount + 1 } ) ;
196205
197- if ( Date . now ( ) - this . state . lastServerDownTimestamp > 6000 && ! document . hidden ) { // if it's 6 seconds since last server down, show a toast
206+ if ( this . state . serverDownCount > 5 && ! document . hidden ) { // if it's 6 seconds since last server down, show a toast
198207 toast . dismiss ( ) ;
199- toast . error ( `Server is down, retrying in ${ timeBetweenFailToast } seconds ...` , { autoClose : ( timeBetweenFailToast - 1 ) * 1000 } ) ;
200- this . setState ( { lastServerDownTimestamp : Date . now ( ) } ) ;
208+ toast . error ( `Server is not responding (retrying ...) ` , { autoClose : ( timeBetweenFailToast - 1 ) * 1000 } ) ;
209+ this . setState ( { isServerDown : true , serverDownCount : 0 } ) ;
201210 }
202211 setTimeout ( ( ) => this . fetchStatsusForever ( ) , failSleepSeconds * 1000 ) ;
203212 } )
204213 }
205214
206215 inIndexing ( ) {
207- return this . state . isPreparingIndexing || this . state . docsInIndexing > 0 || this . state . docsLeftToIndex > 0 ;
216+ return this . state . isPreparingIndexing || this . state . isIndexing ;
208217 }
209218
210219 getIndexingStatusText ( ) {
@@ -213,17 +222,36 @@ export default class App extends React.Component <{}, AppState>{
213222 }
214223
215224 if ( this . state . docsInIndexing > 0 ) {
216- let text = "Indexing " + this . state . docsInIndexing + " documents... it might take a while. " ;
225+ let text = "Indexing " + this . state . docsInIndexing + " documents..." ;
217226 if ( this . state . docsLeftToIndex > 0 ) {
218- text += " (" + this . state . docsLeftToIndex + "~ left in queue)" ;
227+ text += " (" + this . state . docsLeftToIndex + " left in queue" ;
228+ if ( this . state . docsIndexed > 0 ) {
229+ text += ", " + this . state . docsIndexed + " documents are indexed & searchable)" ;
230+ } else {
231+ text += ")" ;
232+ }
233+
234+ } else {
235+ if ( this . state . docsIndexed > 0 ) {
236+ text += " (" + this . state . docsIndexed + " documents are indexed & searchable)" ;
237+ }
219238 }
220239
221240 return text ;
222241 }
223242
224243 if ( this . state . docsLeftToIndex > 0 ) {
225- return "Preparing to index..." ;
244+ let text = "Preparing to index" ;
245+ if ( this . state . docsIndexed > 0 ) {
246+ text += " (" + this . state . docsIndexed + " documents are indexed & searchable)" ;
247+ } else {
248+ text += "..." ;
249+ }
250+ return text ;
226251 }
252+
253+ return `Indexing... (${ this . state . docsIndexed } documents are indexed & searchable)` ;
254+
227255 }
228256
229257 openModal ( ) {
0 commit comments