From 18ceee35414ad61dcd0223a6be43746ed9eef1c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Fernandes?= Date: Mon, 23 Jun 2025 23:55:09 +0100 Subject: [PATCH 1/5] fix: exact matching --- src/utils.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index c7e8cd7..157b4e4 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -113,12 +113,15 @@ export async function findObject( core.debug("Restore keys: " + JSON.stringify(restoreKeys)); core.debug(`Finding exact macth for: ${key}`); - const exactMatch = await listObjects(mc, bucket, key); - core.debug(`Found ${JSON.stringify(exactMatch, null, 2)}`); - if (exactMatch.length) { - const result = { item: exactMatch[0], matchingKey: key }; - core.debug(`Using ${JSON.stringify(result)}`); - return result; + const keyMatches = await listObjects(mc, bucket, key); + core.debug(`Found ${JSON.stringify(keyMatches, null, 2)}`); + if (keyMatches.length > 0) { + const exactMatch = keyMatches.find((obj) => obj.name === key) + if (exactMatch) { + const result = { item: exactMatch, matchingKey: key }; + core.debug(`Using ${JSON.stringify(result)}`); + return result; + } } for (const restoreKey of restoreKeys) { @@ -127,7 +130,7 @@ export async function findObject( let objects = await listObjects(mc, bucket, restoreKey); objects = objects.filter((o) => o.name.includes(fn)); core.debug(`Found ${JSON.stringify(objects, null, 2)}`); - if (objects.length < 1) { + if (objects.length == 0) { continue; } const sorted = objects.sort( From 9d5ebaf2af809a210c6ba05c2532897506869883 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Fernandes?= Date: Tue, 24 Jun 2025 00:07:19 +0100 Subject: [PATCH 2/5] chore: improve logging --- src/utils.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 157b4e4..8f8835c 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -112,17 +112,18 @@ export async function findObject( core.debug("Key: " + JSON.stringify(key)); core.debug("Restore keys: " + JSON.stringify(restoreKeys)); - core.debug(`Finding exact macth for: ${key}`); + core.debug(`Finding exact match for: ${key}`); const keyMatches = await listObjects(mc, bucket, key); core.debug(`Found ${JSON.stringify(keyMatches, null, 2)}`); if (keyMatches.length > 0) { - const exactMatch = keyMatches.find((obj) => obj.name === key) + const exactMatch = keyMatches.find((obj) => obj.name === key); if (exactMatch) { const result = { item: exactMatch, matchingKey: key }; - core.debug(`Using ${JSON.stringify(result)}`); + core.debug(`Found an exact match; using ${JSON.stringify(result)}`); return result; } } + core.debug(`Didn't find an exact match`); for (const restoreKey of restoreKeys) { const fn = utils.getCacheFileName(compressionMethod); From 8a7e86207dc72a3f6bd8cbc23f4f061558fee8f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Fernandes?= Date: Tue, 24 Jun 2025 00:11:09 +0100 Subject: [PATCH 3/5] chore: add new build --- dist/restore/index.js | 20 ++++++++++++-------- dist/save/index.js | 20 ++++++++++++-------- dist/saveOnly/index.js | 20 ++++++++++++-------- 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/dist/restore/index.js b/dist/restore/index.js index 31227c9..76918bf 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -109850,21 +109850,25 @@ function findObject(mc, bucket, key, restoreKeys, compressionMethod) { return __awaiter(this, void 0, void 0, function* () { core.debug("Key: " + JSON.stringify(key)); core.debug("Restore keys: " + JSON.stringify(restoreKeys)); - core.debug(`Finding exact macth for: ${key}`); - const exactMatch = yield listObjects(mc, bucket, key); - core.debug(`Found ${JSON.stringify(exactMatch, null, 2)}`); - if (exactMatch.length) { - const result = { item: exactMatch[0], matchingKey: key }; - core.debug(`Using ${JSON.stringify(result)}`); - return result; + core.debug(`Finding exact match for: ${key}`); + const keyMatches = yield listObjects(mc, bucket, key); + core.debug(`Found ${JSON.stringify(keyMatches, null, 2)}`); + if (keyMatches.length > 0) { + const exactMatch = keyMatches.find((obj) => obj.name === key); + if (exactMatch) { + const result = { item: exactMatch, matchingKey: key }; + core.debug(`Found an exact match; using ${JSON.stringify(result)}`); + return result; + } } + core.debug(`Didn't find an exact match`); for (const restoreKey of restoreKeys) { const fn = utils.getCacheFileName(compressionMethod); core.debug(`Finding object with prefix: ${restoreKey}`); let objects = yield listObjects(mc, bucket, restoreKey); objects = objects.filter((o) => o.name.includes(fn)); core.debug(`Found ${JSON.stringify(objects, null, 2)}`); - if (objects.length < 1) { + if (objects.length == 0) { continue; } const sorted = objects.sort((a, b) => b.lastModified.getTime() - a.lastModified.getTime()); diff --git a/dist/save/index.js b/dist/save/index.js index d3c8df2..07ab806 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -109765,21 +109765,25 @@ function findObject(mc, bucket, key, restoreKeys, compressionMethod) { return __awaiter(this, void 0, void 0, function* () { core.debug("Key: " + JSON.stringify(key)); core.debug("Restore keys: " + JSON.stringify(restoreKeys)); - core.debug(`Finding exact macth for: ${key}`); - const exactMatch = yield listObjects(mc, bucket, key); - core.debug(`Found ${JSON.stringify(exactMatch, null, 2)}`); - if (exactMatch.length) { - const result = { item: exactMatch[0], matchingKey: key }; - core.debug(`Using ${JSON.stringify(result)}`); - return result; + core.debug(`Finding exact match for: ${key}`); + const keyMatches = yield listObjects(mc, bucket, key); + core.debug(`Found ${JSON.stringify(keyMatches, null, 2)}`); + if (keyMatches.length > 0) { + const exactMatch = keyMatches.find((obj) => obj.name === key); + if (exactMatch) { + const result = { item: exactMatch, matchingKey: key }; + core.debug(`Found an exact match; using ${JSON.stringify(result)}`); + return result; + } } + core.debug(`Didn't find an exact match`); for (const restoreKey of restoreKeys) { const fn = utils.getCacheFileName(compressionMethod); core.debug(`Finding object with prefix: ${restoreKey}`); let objects = yield listObjects(mc, bucket, restoreKey); objects = objects.filter((o) => o.name.includes(fn)); core.debug(`Found ${JSON.stringify(objects, null, 2)}`); - if (objects.length < 1) { + if (objects.length == 0) { continue; } const sorted = objects.sort((a, b) => b.lastModified.getTime() - a.lastModified.getTime()); diff --git a/dist/saveOnly/index.js b/dist/saveOnly/index.js index d8774ba..dd70f09 100644 --- a/dist/saveOnly/index.js +++ b/dist/saveOnly/index.js @@ -109765,21 +109765,25 @@ function findObject(mc, bucket, key, restoreKeys, compressionMethod) { return __awaiter(this, void 0, void 0, function* () { core.debug("Key: " + JSON.stringify(key)); core.debug("Restore keys: " + JSON.stringify(restoreKeys)); - core.debug(`Finding exact macth for: ${key}`); - const exactMatch = yield listObjects(mc, bucket, key); - core.debug(`Found ${JSON.stringify(exactMatch, null, 2)}`); - if (exactMatch.length) { - const result = { item: exactMatch[0], matchingKey: key }; - core.debug(`Using ${JSON.stringify(result)}`); - return result; + core.debug(`Finding exact match for: ${key}`); + const keyMatches = yield listObjects(mc, bucket, key); + core.debug(`Found ${JSON.stringify(keyMatches, null, 2)}`); + if (keyMatches.length > 0) { + const exactMatch = keyMatches.find((obj) => obj.name === key); + if (exactMatch) { + const result = { item: exactMatch, matchingKey: key }; + core.debug(`Found an exact match; using ${JSON.stringify(result)}`); + return result; + } } + core.debug(`Didn't find an exact match`); for (const restoreKey of restoreKeys) { const fn = utils.getCacheFileName(compressionMethod); core.debug(`Finding object with prefix: ${restoreKey}`); let objects = yield listObjects(mc, bucket, restoreKey); objects = objects.filter((o) => o.name.includes(fn)); core.debug(`Found ${JSON.stringify(objects, null, 2)}`); - if (objects.length < 1) { + if (objects.length == 0) { continue; } const sorted = objects.sort((a, b) => b.lastModified.getTime() - a.lastModified.getTime()); From fd3c067027b0a7d41a247d0c022c4ebf9605020d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Fernandes?= Date: Fri, 26 Sep 2025 01:31:17 +0100 Subject: [PATCH 4/5] fix: output cache-hit This isn't perfect, since using `startsWith` doesn't really guarantee an exact match, but it's good enough and certainly better than what I found. --- src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.ts b/src/utils.ts index 8f8835c..1d398ef 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -116,7 +116,7 @@ export async function findObject( const keyMatches = await listObjects(mc, bucket, key); core.debug(`Found ${JSON.stringify(keyMatches, null, 2)}`); if (keyMatches.length > 0) { - const exactMatch = keyMatches.find((obj) => obj.name === key); + const exactMatch = keyMatches.find((obj) => obj.name.startsWith(key)); if (exactMatch) { const result = { item: exactMatch, matchingKey: key }; core.debug(`Found an exact match; using ${JSON.stringify(result)}`); From 9c316ce988fd9d40977dad01d0c7fa06792fa0da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Fernandes?= Date: Fri, 26 Sep 2025 01:32:16 +0100 Subject: [PATCH 5/5] chore: update build --- dist/restore/index.js | 2 +- dist/save/index.js | 2 +- dist/saveOnly/index.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/restore/index.js b/dist/restore/index.js index 76918bf..c0b3b74 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -109854,7 +109854,7 @@ function findObject(mc, bucket, key, restoreKeys, compressionMethod) { const keyMatches = yield listObjects(mc, bucket, key); core.debug(`Found ${JSON.stringify(keyMatches, null, 2)}`); if (keyMatches.length > 0) { - const exactMatch = keyMatches.find((obj) => obj.name === key); + const exactMatch = keyMatches.find((obj) => obj.name.startsWith(key)); if (exactMatch) { const result = { item: exactMatch, matchingKey: key }; core.debug(`Found an exact match; using ${JSON.stringify(result)}`); diff --git a/dist/save/index.js b/dist/save/index.js index 07ab806..7388d9c 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -109769,7 +109769,7 @@ function findObject(mc, bucket, key, restoreKeys, compressionMethod) { const keyMatches = yield listObjects(mc, bucket, key); core.debug(`Found ${JSON.stringify(keyMatches, null, 2)}`); if (keyMatches.length > 0) { - const exactMatch = keyMatches.find((obj) => obj.name === key); + const exactMatch = keyMatches.find((obj) => obj.name.startsWith(key)); if (exactMatch) { const result = { item: exactMatch, matchingKey: key }; core.debug(`Found an exact match; using ${JSON.stringify(result)}`); diff --git a/dist/saveOnly/index.js b/dist/saveOnly/index.js index dd70f09..b94cd03 100644 --- a/dist/saveOnly/index.js +++ b/dist/saveOnly/index.js @@ -109769,7 +109769,7 @@ function findObject(mc, bucket, key, restoreKeys, compressionMethod) { const keyMatches = yield listObjects(mc, bucket, key); core.debug(`Found ${JSON.stringify(keyMatches, null, 2)}`); if (keyMatches.length > 0) { - const exactMatch = keyMatches.find((obj) => obj.name === key); + const exactMatch = keyMatches.find((obj) => obj.name.startsWith(key)); if (exactMatch) { const result = { item: exactMatch, matchingKey: key }; core.debug(`Found an exact match; using ${JSON.stringify(result)}`);