Skip to content

Commit

Permalink
fix: 修复revalidate出错
Browse files Browse the repository at this point in the history
  • Loading branch information
烫宝 committed Mar 8, 2024
1 parent 6664189 commit c16139b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 4 additions & 1 deletion app/core/service/BinarySyncerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ export class BinarySyncerService extends AbstractService {
for (const item of existsItems) {
existsMap.set(item.name, item);
}
const latestItem = sortBy(fetchItems, item => {
return new Date(item.date);
}).pop();
const diffItems: { item: Binary; reason: string }[] = [];
for (const item of fetchItems) {
const existsItem = existsMap.get(item.name);
Expand All @@ -276,7 +279,7 @@ export class BinarySyncerService extends AbstractService {
existsItem.ignoreDownloadStatuses = item.ignoreDownloadStatuses;
existsItem.date = item.date;
} else if (dir.endsWith(latestVersionParent)) {
const isLatestItem = sortBy(fetchItems, [ 'date' ]).pop()?.name === item.name;
const isLatestItem = latestItem?.name === item.name;
if (isLatestItem && existsItem.isDir) {
diffItems.push({
item: existsItem,
Expand Down
9 changes: 6 additions & 3 deletions test/core/service/BinarySyncerService/executeTask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ describe('test/core/service/BinarySyncerService/executeTask.test.ts', () => {
return {
items: [
{ name: 'latest/', isDir: true, url: '', size: '-', date: '17-Dec-2021 23:17' },
{ name: 'old/', isDir: true, url: '', size: '-', date: '15-Dec-2021 23:17' },
// old2 使用 yyyy-mm-dd 日期格式,用于检查 diff 的日期排序

Check failure on line 300 in test/core/service/BinarySyncerService/executeTask.test.ts

View workflow job for this annotation

GitHub Actions / test-mysql57-fs-nfs (16, ubuntu-latest)

Expected indentation of 14 spaces but found 16

Check failure on line 300 in test/core/service/BinarySyncerService/executeTask.test.ts

View workflow job for this annotation

GitHub Actions / test-mysql57-fs-nfs (18, ubuntu-latest)

Expected indentation of 14 spaces but found 16

Check failure on line 300 in test/core/service/BinarySyncerService/executeTask.test.ts

View workflow job for this annotation

GitHub Actions / test-mysql57-fs-nfs (20, ubuntu-latest)

Expected indentation of 14 spaces but found 16
{ name: 'old2/', isDir: true, url: '', size: '-', date: '2021-11-10T05:49:35.321Z' },
{ name: 'index.json', isDir: false, url: 'https://nodejs.org/dist/index.json', size: '219862', date: '17-Dec-2021 23:16' },
],
};
Expand Down Expand Up @@ -324,7 +327,7 @@ describe('test/core/service/BinarySyncerService/executeTask.test.ts', () => {
assert(stream);
let log = await TestUtil.readStreamToLog(stream);
// console.log(log);
assert(log.includes('Syncing diff: 2 => 2'));
assert(log.includes('Syncing diff: 4 => 4'));
assert(log.includes('[/] 🟢 Synced dir success'));
assert(log.includes('[/latest/] 🟢 Synced dir success'));
assert(log.includes('[/latest/docs/] 🟢 Synced dir success'));
Expand All @@ -339,9 +342,9 @@ describe('test/core/service/BinarySyncerService/executeTask.test.ts', () => {
log = await TestUtil.readStreamToLog(stream);
// console.log(log);
assert(log.includes('reason: revalidate latest version'));
assert(log.includes('Syncing diff: 2 => 1'));
assert(log.includes('Syncing diff: 4 => 1'));
assert(log.includes('[/] 🟢 Synced dir success'));

assert(log.includes('[/latest/] 🟢 Synced dir success'));
// mock version change
// console.log(binaryRepository.findBinary('node'));

Expand Down

0 comments on commit c16139b

Please sign in to comment.