Skip to content

Commit fd395f6

Browse files
Merge pull request #424 from GSA/lc/1286-update-snapshots
1286 - Update, create new snapshots
2 parents dfcb371 + 5505a5f commit fd395f6

File tree

5 files changed

+69
-2
lines changed

5 files changed

+69
-2
lines changed

libs/database/src/websites/websites.service.integration.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ describe('AnalysisService', () => {
8181
firstCoreResult.sitemapXmlScanStatus = 'complete';
8282
firstCoreResult.targetUrlBaseDomain = 'complete';
8383
firstCoreResult.finalUrlMIMEType = 'text/html';
84+
firstCoreResult.filter = false;
8485

8586
const secondCoreResult = new CoreResult();
8687
secondCoreResult.website = secondWebsite;
@@ -91,6 +92,7 @@ describe('AnalysisService', () => {
9192
secondCoreResult.sitemapXmlScanStatus = 'complete';
9293
secondCoreResult.targetUrlBaseDomain = 'complete';
9394
secondCoreResult.finalUrlMIMEType = 'text/html';
95+
secondCoreResult.filter = false;
9496

9597
const thirdCoreResult = new CoreResult();
9698
thirdCoreResult.website = thirdWebsite;
@@ -101,6 +103,7 @@ describe('AnalysisService', () => {
101103
thirdCoreResult.sitemapXmlScanStatus = 'complete';
102104
thirdCoreResult.targetUrlBaseDomain = 'complete';
103105
thirdCoreResult.finalUrlMIMEType = 'application/json';
106+
thirdCoreResult.filter = false;
104107

105108
const fourthCoreResult = new CoreResult();
106109
fourthCoreResult.website = fourthWebsite;
@@ -111,6 +114,7 @@ describe('AnalysisService', () => {
111114
fourthCoreResult.sitemapXmlScanStatus = 'complete';
112115
fourthCoreResult.targetUrlBaseDomain = 'complete';
113116
fourthCoreResult.finalUrlMIMEType = 'application/html';
117+
fourthCoreResult.filter = false;
114118

115119
await websiteRepository.insert(firstWebsite);
116120
await coreResultRepository.insert(firstCoreResult);

libs/database/src/websites/websites.service.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,30 @@ export class WebsiteService {
3030
const queryBuilder = this.website
3131
.createQueryBuilder('website')
3232
.innerJoinAndSelect('website.coreResult', 'coreResult')
33+
.andWhere('coreResult.filter = :isFilter', { isFilter: false })
3334
.andWhere('coreResult.finalUrlIsLive = :isLive', { isLive: true })
3435
.andWhere('coreResult.finalUrlMIMEType NOT IN (:...mimeTypes)', {
3536
mimeTypes: [
36-
'application/xhtml+xml',
37+
'image/jpeg',
38+
'application/xml',
39+
'application/json',
40+
'text/xml',
41+
],
42+
});
43+
44+
return await queryBuilder.getMany();
45+
}
46+
47+
async findUniqueSnapshotResults(): Promise<Website[]> {
48+
const queryBuilder = this.website
49+
.createQueryBuilder('website')
50+
.innerJoinAndSelect('website.coreResult', 'coreResult')
51+
.andWhere('coreResult.filter = :isFilter', { isFilter: false })
52+
.andWhere('coreResult.targetUrlRedirects = :isRedirect', { isRedirect: false })
53+
.andWhere('coreResult.finalUrlIsLive = :isLive', { isLive: true })
54+
.andWhere('coreResult.finalUrlMIMEType NOT IN (:...mimeTypes)', {
55+
mimeTypes: [
56+
'image/jpeg',
3757
'application/xml',
3858
'application/json',
3959
'text/xml',

libs/snapshot/src/config/snapshot.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ export default () => {
55
if (process.env.NODE_ENV === 'production') {
66
return {
77
fileNameLive: 'weekly-snapshot',
8+
fileNameUnique: 'weekly-snapshot-unique',
89
fileNameAll: 'weekly-snapshot-all',
910
fileNameAccessibility: 'weekly-snapshot-accessibility-details',
1011
};
1112
} else {
1213
return {
1314
fileNameLive: `weekly-snapshot-${process.env.NODE_ENV}`,
15+
fileNameUnique: `weekly-snapshot-unique-${process.env.NODE_ENV}`,
1416
fileNameAll: `weekly-snapshot-all-${process.env.NODE_ENV}`,
1517
fileNameAccessibility: `weekly-snapshot-accessibility-details-${process.env.NODE_ENV}`,
1618
};

libs/snapshot/src/snapshot.service.spec.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ describe('SnapshotService', () => {
4343
return 'weekly-snapshot';
4444
}
4545

46+
if (key === 'fileNameUnique') {
47+
return 'weekly-snapshot-unique';
48+
}
49+
4650
if (key === 'fileNameAll') {
4751
return 'weekly-snapshot-all';
4852
}
@@ -80,14 +84,15 @@ describe('SnapshotService', () => {
8084
website.url = 'supremecourt.gov';
8185

8286
mockWebsiteService.findLiveSnapshotResults.mockResolvedValue([website]);
87+
mockWebsiteService.findUniqueSnapshotResults.mockResolvedValue([website]);
8388
mockWebsiteService.findAllSnapshotResults.mockResolvedValue([website]);
8489

8590
await service.weeklySnapshot();
8691

8792
copyDate.setDate(copyDate.getDate() - 7);
8893
const expectedDate = copyDate.toISOString();
8994

90-
expect(mockStorageService.copy).toBeCalledTimes(4);
95+
expect(mockStorageService.copy).toBeCalledTimes(6);
9196

9297
expect(mockStorageService.copy).toBeCalledWith(
9398
'weekly-snapshot.json',
@@ -99,6 +104,16 @@ describe('SnapshotService', () => {
99104
`archive/csv/weekly-snapshot-${expectedDate}.csv`,
100105
);
101106

107+
expect(mockStorageService.copy).toBeCalledWith(
108+
'weekly-snapshot-unique.json',
109+
`archive/json/weekly-snapshot-unique-${expectedDate}.json`,
110+
);
111+
112+
expect(mockStorageService.copy).toBeCalledWith(
113+
'weekly-snapshot-unique.csv',
114+
`archive/csv/weekly-snapshot-unique-${expectedDate}.csv`,
115+
);
116+
102117
expect(mockStorageService.copy).toBeCalledWith(
103118
'weekly-snapshot-all.json',
104119
`archive/json/weekly-snapshot-all-${expectedDate}.json`,

libs/snapshot/src/snapshot.service.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export class SnapshotService {
2020
) {}
2121

2222
private fileNameLive = this.configService.get<string>('fileNameLive');
23+
private fileNameUnique = this.configService.get<string>('fileNameUnique');
2324
private fileNameAll = this.configService.get<string>('fileNameAll');
2425
private fileNameAccessibility = this.configService.get<string>(
2526
'fileNameAccessibility',
@@ -42,6 +43,7 @@ export class SnapshotService {
4243
const priorDate = date.toISOString();
4344

4445
await this.liveSnapshot(priorDate, CoreResult.snapshotColumnOrder);
46+
await this.uniqueSnapshot(priorDate, CoreResult.snapshotColumnOrder);
4547
await this.allSnapshot(priorDate, CoreResult.snapshotColumnOrder);
4648
}
4749

@@ -69,6 +71,30 @@ export class SnapshotService {
6971
liveSnapshot = null;
7072
}
7173

74+
async uniqueSnapshot(date: string, columns: string[]): Promise<void> {
75+
let uniqueWebsites = await this.websiteService.findUniqueSnapshotResults();
76+
this.logger.log(
77+
`Total number of unique websites retrieved for snapshot: ${uniqueWebsites.length}`,
78+
);
79+
80+
let uniqueSnapshot = new Snapshot(
81+
this.storageService,
82+
[new JsonSerializer(columns), new CsvSerializer(columns)],
83+
uniqueWebsites,
84+
date,
85+
this.fileNameUnique,
86+
);
87+
88+
await uniqueSnapshot.archiveExisting();
89+
this.logger.log('Unique snapshot archived.');
90+
91+
await uniqueSnapshot.saveNew();
92+
this.logger.log('Unique snapshot saved.');
93+
94+
uniqueWebsites = null;
95+
uniqueSnapshot = null;
96+
}
97+
7298
async allSnapshot(date: string, columns: string[]) {
7399
let allWebsites = await this.websiteService.findAllSnapshotResults();
74100
this.logger.log(

0 commit comments

Comments
 (0)