Skip to content

Commit c16139b

Browse files
author
烫宝
committed
fix: 修复revalidate出错
1 parent 6664189 commit c16139b

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

app/core/service/BinarySyncerService.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ export class BinarySyncerService extends AbstractService {
250250
for (const item of existsItems) {
251251
existsMap.set(item.name, item);
252252
}
253+
const latestItem = sortBy(fetchItems, item => {
254+
return new Date(item.date);
255+
}).pop();
253256
const diffItems: { item: Binary; reason: string }[] = [];
254257
for (const item of fetchItems) {
255258
const existsItem = existsMap.get(item.name);
@@ -276,7 +279,7 @@ export class BinarySyncerService extends AbstractService {
276279
existsItem.ignoreDownloadStatuses = item.ignoreDownloadStatuses;
277280
existsItem.date = item.date;
278281
} else if (dir.endsWith(latestVersionParent)) {
279-
const isLatestItem = sortBy(fetchItems, [ 'date' ]).pop()?.name === item.name;
282+
const isLatestItem = latestItem?.name === item.name;
280283
if (isLatestItem && existsItem.isDir) {
281284
diffItems.push({
282285
item: existsItem,

test/core/service/BinarySyncerService/executeTask.test.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ describe('test/core/service/BinarySyncerService/executeTask.test.ts', () => {
296296
return {
297297
items: [
298298
{ name: 'latest/', isDir: true, url: '', size: '-', date: '17-Dec-2021 23:17' },
299+
{ name: 'old/', isDir: true, url: '', size: '-', date: '15-Dec-2021 23:17' },
300+
// old2 使用 yyyy-mm-dd 日期格式,用于检查 diff 的日期排序
301+
{ name: 'old2/', isDir: true, url: '', size: '-', date: '2021-11-10T05:49:35.321Z' },
299302
{ name: 'index.json', isDir: false, url: 'https://nodejs.org/dist/index.json', size: '219862', date: '17-Dec-2021 23:16' },
300303
],
301304
};
@@ -324,7 +327,7 @@ describe('test/core/service/BinarySyncerService/executeTask.test.ts', () => {
324327
assert(stream);
325328
let log = await TestUtil.readStreamToLog(stream);
326329
// console.log(log);
327-
assert(log.includes('Syncing diff: 2 => 2'));
330+
assert(log.includes('Syncing diff: 4 => 4'));
328331
assert(log.includes('[/] 🟢 Synced dir success'));
329332
assert(log.includes('[/latest/] 🟢 Synced dir success'));
330333
assert(log.includes('[/latest/docs/] 🟢 Synced dir success'));
@@ -339,9 +342,9 @@ describe('test/core/service/BinarySyncerService/executeTask.test.ts', () => {
339342
log = await TestUtil.readStreamToLog(stream);
340343
// console.log(log);
341344
assert(log.includes('reason: revalidate latest version'));
342-
assert(log.includes('Syncing diff: 2 => 1'));
345+
assert(log.includes('Syncing diff: 4 => 1'));
343346
assert(log.includes('[/] 🟢 Synced dir success'));
344-
347+
assert(log.includes('[/latest/] 🟢 Synced dir success'));
345348
// mock version change
346349
// console.log(binaryRepository.findBinary('node'));
347350

0 commit comments

Comments
 (0)