Skip to content

Commit b4e39dd

Browse files
committed
prettier fix
1 parent 46a9c18 commit b4e39dd

File tree

2 files changed

+41
-49
lines changed

2 files changed

+41
-49
lines changed

packages/cloudflare/src/api/overrides/tag-cache/do-sharded-tag-cache.spec.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ describe("DOShardedTagCache", () => {
212212

213213
it("should return false if stub return false", async () => {
214214
const cache = shardedDOTagCache();
215-
cache.getFromRegionalCache = vi.fn().mockResolvedValueOnce([])
215+
cache.getFromRegionalCache = vi.fn().mockResolvedValueOnce([]);
216216
hasBeenRevalidatedMock.mockImplementationOnce(() => false);
217217
const result = await cache.hasBeenRevalidated(["tag1"], 123456);
218218
expect(cache.getFromRegionalCache).toHaveBeenCalled();
@@ -257,7 +257,7 @@ describe("DOShardedTagCache", () => {
257257
it("should try to put the result in the cache if it was not revalidated", async () => {
258258
const cache = shardedDOTagCache();
259259
cache.getFromRegionalCache = vi.fn().mockResolvedValueOnce([]);
260-
cache.putToRegionalCache = vi.fn()
260+
cache.putToRegionalCache = vi.fn();
261261
hasBeenRevalidatedMock.mockImplementationOnce(() => false);
262262
const result = await cache.hasBeenRevalidated(["tag1"], 123456);
263263
expect(result).toBe(false);
@@ -367,14 +367,14 @@ describe("DOShardedTagCache", () => {
367367
numberOfReplicas: 1,
368368
shardType: "hard",
369369
});
370-
expect(await cache.getFromRegionalCache({ doId, tags: ["tag1"] })).toEqual([])
370+
expect(await cache.getFromRegionalCache({ doId, tags: ["tag1"] })).toEqual([]);
371371
});
372372

373373
it("should call .match on the cache", async () => {
374374
// @ts-expect-error - Defined on cloudfare context
375375
globalThis.caches = {
376376
open: vi.fn().mockResolvedValue({
377-
match: vi.fn().mockResolvedValue(new Response('1234567')),
377+
match: vi.fn().mockResolvedValue(new Response("1234567")),
378378
}),
379379
};
380380
const cache = shardedDOTagCache({ baseShardSize: 4, regionalCache: true });
@@ -404,9 +404,7 @@ describe("DOShardedTagCache", () => {
404404
numberOfReplicas: 1,
405405
shardType: "hard",
406406
});
407-
expect(cache.getCacheUrlKey(doId2, "tag1")).toBe(
408-
"http://local.cache/shard/tag-hard;shard-1?tag=tag1"
409-
);
407+
expect(cache.getCacheUrlKey(doId2, "tag1")).toBe("http://local.cache/shard/tag-hard;shard-1?tag=tag1");
410408
});
411409
});
412410

packages/cloudflare/src/api/overrides/tag-cache/do-sharded-tag-cache.ts

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -197,23 +197,23 @@ class ShardedDOTagCache implements NextModeTagCache {
197197
// If we have regional replication enabled, we need to further duplicate the shards in all the regions
198198
const regionalReplicasInAllRegions = generateAllReplicas
199199
? regionalReplicas.flatMap(({ doId, tag }) => {
200-
return AVAILABLE_REGIONS.map((region) => {
201-
return {
202-
doId: new DOId({
203-
baseShardId: doId.options.baseShardId,
204-
numberOfReplicas: numReplicas,
205-
shardType,
206-
replicaId: doId.replicaId,
207-
region,
208-
}),
209-
tag,
210-
};
211-
});
212-
})
200+
return AVAILABLE_REGIONS.map((region) => {
201+
return {
202+
doId: new DOId({
203+
baseShardId: doId.options.baseShardId,
204+
numberOfReplicas: numReplicas,
205+
shardType,
206+
replicaId: doId.replicaId,
207+
region,
208+
}),
209+
tag,
210+
};
211+
});
212+
})
213213
: regionalReplicas.map(({ doId, tag }) => {
214-
doId.region = this.getClosestRegion();
215-
return { doId, tag };
216-
});
214+
doId.region = this.getClosestRegion();
215+
return { doId, tag };
216+
});
217217
return regionalReplicasInAllRegions;
218218
}
219219

@@ -286,9 +286,9 @@ class ShardedDOTagCache implements NextModeTagCache {
286286
return !db || isDisabled
287287
? { isDisabled: true as const }
288288
: {
289-
isDisabled: false as const,
290-
db,
291-
};
289+
isDisabled: false as const,
290+
db,
291+
};
292292
}
293293

294294
async getLastRevalidated(tags: string[]): Promise<number> {
@@ -311,15 +311,10 @@ class ShardedDOTagCache implements NextModeTagCache {
311311
const stub = this.getDurableObjectStub(doId);
312312
const lastRevalidated = await stub.getLastRevalidated(filteredTags);
313313

314-
const result = Math.max(
315-
...cachedValue.map((item) => item.time),
316-
lastRevalidated
317-
);
314+
const result = Math.max(...cachedValue.map((item) => item.time), lastRevalidated);
318315

319316
// We then need to populate the regional cache with the missing tags
320-
getCloudflareContext().ctx.waitUntil(
321-
this.putToRegionalCache({ doId, tags }, stub)
322-
);
317+
getCloudflareContext().ctx.waitUntil(this.putToRegionalCache({ doId, tags }, stub));
323318

324319
return result;
325320
})
@@ -402,9 +397,7 @@ class ShardedDOTagCache implements NextModeTagCache {
402397
await stub.writeTags(tags, lastModified);
403398
// Depending on the shards and the tags, deleting from the regional cache will not work for every tag
404399
// We also need to delete both cache
405-
await Promise.all([
406-
this.deleteRegionalCache({ doId, tags }),
407-
]);
400+
await Promise.all([this.deleteRegionalCache({ doId, tags })]);
408401
} catch (e) {
409402
error("Error while writing tags", e);
410403
if (retryNumber >= this.maxWriteRetries) {
@@ -433,9 +426,6 @@ class ShardedDOTagCache implements NextModeTagCache {
433426
return `http://local.cache/shard/${doId.shardId}?tag=${encodeURIComponent(tag)}`;
434427
}
435428

436-
437-
438-
439429
/**
440430
* Get the last revalidation time for the tags from the regional cache
441431
* If the cache is not enabled, it will return an empty array
@@ -477,16 +467,20 @@ class ShardedDOTagCache implements NextModeTagCache {
477467
if (lastRevalidated === undefined) return; // Should we store something in the cache if the tag is not found ?
478468
const cacheKey = this.getCacheUrlKey(optsKey.doId, tag);
479469
debugCache("Putting to regional cache", { cacheKey, lastRevalidated });
480-
await cache.put(cacheKey, new Response(lastRevalidated.toString(), {
481-
status: 200, headers: {
482-
"cache-control": `max-age=${this.opts.regionalCacheTtlSec ?? 5}`,
483-
...(tags.length > 0
484-
? {
485-
"cache-tag": tags.join(","),
486-
}
487-
: {})
488-
}
489-
}));
470+
await cache.put(
471+
cacheKey,
472+
new Response(lastRevalidated.toString(), {
473+
status: 200,
474+
headers: {
475+
"cache-control": `max-age=${this.opts.regionalCacheTtlSec ?? 5}`,
476+
...(tags.length > 0
477+
? {
478+
"cache-tag": tags.join(","),
479+
}
480+
: {}),
481+
},
482+
})
483+
);
490484
})
491485
);
492486
}

0 commit comments

Comments
 (0)