s3-querier 1.2.1 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/s3/s3.js +18 -13
- package/src/utils/logger.js +1 -1
package/package.json
CHANGED
package/src/s3/s3.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fsPromise from 'node:fs/promises';
|
|
2
2
|
import { dirname } from 'node:path';
|
|
3
|
-
import { S3Client,
|
|
3
|
+
import { S3Client, paginateListObjectsV2, GetObjectCommand } from '@aws-sdk/client-s3';
|
|
4
4
|
|
|
5
5
|
import { logger } from '../utils/logger.js';
|
|
6
6
|
import { datesInRange, hoursInRange, monthsInRange, buildPath } from '../utils/file-path-builder/file-path-builder.js';
|
|
@@ -103,8 +103,7 @@ export default class S3 {
|
|
|
103
103
|
|
|
104
104
|
return Promise.allSettled(listPromises).then((results) => {
|
|
105
105
|
const regex = regexFromPattern(file);
|
|
106
|
-
|
|
107
|
-
this.listingCache.delete(`${this.bucket}/${todayPrefix}`);
|
|
106
|
+
this.evictTodayFromListingCache(file);
|
|
108
107
|
|
|
109
108
|
return results
|
|
110
109
|
.filter((result) => result.status === 'fulfilled')
|
|
@@ -225,6 +224,19 @@ export default class S3 {
|
|
|
225
224
|
return buildPath(`${trimmed}{dd}`, new Date());
|
|
226
225
|
}
|
|
227
226
|
|
|
227
|
+
/**
|
|
228
|
+
* Removes all listing cache entries whose key falls under today's day prefix.
|
|
229
|
+
* Covers day-level, hour-level, and minute-level cache keys in one pass.
|
|
230
|
+
*
|
|
231
|
+
* @param {string} filePattern File pattern
|
|
232
|
+
*/
|
|
233
|
+
evictTodayFromListingCache(filePattern) {
|
|
234
|
+
const todayPrefix = `${this.bucket}/${this.getTodayPrefix(filePattern)}`;
|
|
235
|
+
[...this.listingCache.keys()]
|
|
236
|
+
.filter((key) => key.startsWith(todayPrefix))
|
|
237
|
+
.forEach((key) => this.listingCache.delete(key));
|
|
238
|
+
}
|
|
239
|
+
|
|
228
240
|
/**
|
|
229
241
|
* Returns a list of files from S3 under the given prefix
|
|
230
242
|
*
|
|
@@ -238,16 +250,9 @@ export default class S3 {
|
|
|
238
250
|
}
|
|
239
251
|
|
|
240
252
|
const files = [];
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
new ListObjectsV2Command({ Bucket: this.bucket, Prefix: prefix, ContinuationToken: continuationToken }),
|
|
245
|
-
);
|
|
246
|
-
response.Contents?.forEach((content) => {
|
|
247
|
-
files.push({ file: content.Key, size: content.Size });
|
|
248
|
-
});
|
|
249
|
-
continuationToken = response.NextContinuationToken;
|
|
250
|
-
} while (continuationToken);
|
|
253
|
+
for await (const page of paginateListObjectsV2({ client: this.s3 }, { Bucket: this.bucket, Prefix: prefix })) {
|
|
254
|
+
page.Contents?.forEach((content) => files.push({ file: content.Key, size: content.Size }));
|
|
255
|
+
}
|
|
251
256
|
|
|
252
257
|
this.listingCache.set(cacheKey, files);
|
|
253
258
|
return files;
|
package/src/utils/logger.js
CHANGED