Skip to content

Commit

Permalink
missingInDB files now also report lastUpdated date (#7507)
Browse files Browse the repository at this point in the history
  • Loading branch information
daneryl authored Nov 29, 2024
1 parent d686555 commit 9091936
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
8 changes: 7 additions & 1 deletion app/api/files.v2/FilesHealthCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { FilesDataSource } from './contracts/FilesDataSource';
import { FileStorage } from './contracts/FileStorage';
import { StoredFile } from './model/StoredFile';
import { URLAttachment } from './model/URLAttachment';

function filterFilesInStorage(files: StoredFile[]) {
return files.filter(
file =>
Expand All @@ -14,6 +15,7 @@ function filterFilesInStorage(files: StoredFile[]) {
type missingInDBFileDTO = {
filename: string;
checksumMatchCount: number;
lastModified?: Date;
};

export class FilesHealthCheck {
Expand Down Expand Up @@ -69,7 +71,11 @@ export class FilesHealthCheck {
if (checksumMatchCount > 1) {
counters.missingInDbWithChecksumMatches += 1;
}
this.onMissingInDBCB({ filename: storedFile.fullPath, checksumMatchCount });
this.onMissingInDBCB({
filename: storedFile.fullPath,
checksumMatchCount,
lastModified: storedFile.lastModified,
});
});

return {
Expand Down
2 changes: 1 addition & 1 deletion app/api/files.v2/infrastructure/S3FileStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ export class S3FileStorage implements FileStorage {
continuationToken = await requestNext(continuationToken);
}

return objects.map(c => new StoredFile(c.Key!, c.ETag!));
return objects.map(c => new StoredFile(c.Key!, c.LastModified, c.ETag!));
}
}
5 changes: 4 additions & 1 deletion app/api/files.v2/model/StoredFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ export class StoredFile {

readonly fullPath: string;

readonly lastModified?: Date;

readonly checksum?: string;

constructor(fullPath: string, checksum?: string) {
constructor(fullPath: string, lastModified?: Date, checksum?: string) {
this.filename = path.basename(fullPath);
this.fullPath = fullPath;
this.checksum = checksum;
this.lastModified = lastModified;
}
}
20 changes: 10 additions & 10 deletions app/api/files.v2/specs/FilesHealthCheck.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ describe('FilesHealthCheck', () => {

it('should emit the count of duplicated checksums for each file emited', async () => {
testStorageFiles = [
new StoredFile('document/file1', 'checksum1'),
new StoredFile('document/file2', 'checksum2'),
new StoredFile('document/file1', new Date(), 'checksum1'),
new StoredFile('document/file2', new Date(), 'checksum2'),
new StoredFile('document/file3'),
new StoredFile('document/file4', 'checksum1'),
new StoredFile('document/file5', 'checksum1'),
new StoredFile('document/file6', 'checksum2'),
new StoredFile('document/file4', new Date(), 'checksum1'),
new StoredFile('document/file5', new Date(), 'checksum1'),
new StoredFile('document/file6', new Date(), 'checksum2'),
];
await testingEnvironment.setUp({ files: [] });

Expand All @@ -211,12 +211,12 @@ describe('FilesHealthCheck', () => {

it('should emit in the summary the number of files which have a checksum match count > 1', async () => {
testStorageFiles = [
new StoredFile('document/file1', 'checksum1'),
new StoredFile('document/file2', 'checksum2'),
new StoredFile('document/file1', new Date(), 'checksum1'),
new StoredFile('document/file2', new Date(), 'checksum2'),
new StoredFile('document/file3'),
new StoredFile('document/file4', 'checksum1'),
new StoredFile('document/file5', 'checksum1'),
new StoredFile('document/file6', 'checksum2'),
new StoredFile('document/file4', new Date(), 'checksum1'),
new StoredFile('document/file5', new Date(), 'checksum1'),
new StoredFile('document/file6', new Date(), 'checksum2'),
];
await testingEnvironment.setUp({ files: [] });

Expand Down

0 comments on commit 9091936

Please sign in to comment.