@@ -121,26 +121,50 @@ export class CurrentRun {
121
121
this . #render = render ;
122
122
}
123
123
124
- static async fromScratch ( current : CurrentRun ) : Promise < IndexResults > {
124
+ static async fromScratch (
125
+ current : CurrentRun ,
126
+ invalidateEntireRealm ?: boolean ,
127
+ ) : Promise < IndexResults > {
125
128
let start = Date . now ( ) ;
126
129
log . debug ( `starting from scratch indexing` ) ;
127
130
console . log (
128
131
`starting from scratch indexing for realm ${ current . realmURL . href } ` ,
129
132
) ;
130
133
131
134
current . #batch = await current . #indexWriter. createBatch ( current . realmURL ) ;
132
- let mtimesStart = Date . now ( ) ;
133
- let mtimes = await current . batch . getModifiedTimes ( ) ;
134
- console . log (
135
- `completed getting index mtimes in ${ Date . now ( ) - mtimesStart } ms` ,
136
- ) ;
137
- let invalidateStart = Date . now ( ) ;
138
- let invalidations = (
139
- await current . discoverInvalidations ( current . realmURL , mtimes )
140
- ) . map ( ( href ) => new URL ( href ) ) ;
141
- console . log (
142
- `completed invalidations in ${ Date . now ( ) - invalidateStart } ms` ,
143
- ) ;
135
+ let invalidations : URL [ ] = [ ] ;
136
+ if ( invalidateEntireRealm ) {
137
+ console . log (
138
+ `flag was set to invalidate entire realm ${ current . realmURL . href } , skipping invalidation discovery` ,
139
+ ) ;
140
+ let mtimesStart = Date . now ( ) ;
141
+ let filesystemMtimes = await current . #reader. mtimes ( ) ;
142
+ console . log (
143
+ `time to get file system mtimes ${ Date . now ( ) - mtimesStart } ms` ,
144
+ ) ;
145
+ invalidations = Object . keys ( filesystemMtimes )
146
+ . filter (
147
+ ( url ) =>
148
+ // Only allow json and executable files to be invalidated so that we
149
+ // don't end up with invalidated files that weren't meant to be indexed
150
+ // (images, etc)
151
+ url . endsWith ( '.json' ) || hasExecutableExtension ( url ) ,
152
+ )
153
+ . map ( ( url ) => new URL ( url ) ) ;
154
+ } else {
155
+ let mtimesStart = Date . now ( ) ;
156
+ let mtimes = await current . batch . getModifiedTimes ( ) ;
157
+ console . log (
158
+ `completed getting index mtimes in ${ Date . now ( ) - mtimesStart } ms` ,
159
+ ) ;
160
+ let invalidateStart = Date . now ( ) ;
161
+ invalidations = (
162
+ await current . discoverInvalidations ( current . realmURL , mtimes )
163
+ ) . map ( ( href ) => new URL ( href ) ) ;
164
+ console . log (
165
+ `completed invalidations in ${ Date . now ( ) - invalidateStart } ms` ,
166
+ ) ;
167
+ }
144
168
145
169
await current . whileIndexing ( async ( ) => {
146
170
let visitStart = Date . now ( ) ;
@@ -299,17 +323,9 @@ export class CurrentRun {
299
323
if ( skipList . length === 0 ) {
300
324
// the whole realm needs to be visited, no need to calculate
301
325
// invalidations--it's everything
302
- console . log (
303
- `entire realm ${ this . realmURL . href } is invalidated--skipping invalidation calculation` ,
304
- ) ;
305
326
return invalidationList ;
306
327
}
307
328
308
- console . log (
309
- `unable to use optimized invalidation for realm ${
310
- this . realmURL . href
311
- } , skipped these files ${ JSON . stringify ( skipList ) } `,
312
- ) ;
313
329
let invalidationStart = Date . now ( ) ;
314
330
for ( let invalidationURL of invalidationList ) {
315
331
await this . batch . invalidate ( new URL ( invalidationURL ) ) ;
0 commit comments