Skip to content

Commit 4007da7

Browse files
committed
Remove unused getDerivedTags() function
1 parent 746d73a commit 4007da7

File tree

1 file changed

+25
-31
lines changed

1 file changed

+25
-31
lines changed

packages/open-next/src/adapters/cache.ts

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import path from "path";
12
import {
23
BatchWriteItemCommand,
34
DynamoDBClient,
@@ -12,15 +13,8 @@ import {
1213
PutObjectCommandOutput,
1314
S3Client,
1415
} from "@aws-sdk/client-s3";
15-
// //@ts-ignore
16-
// import { getDerivedTags } from "next/dist/server/lib/incremental-cache/utils";
17-
import path from "path";
18-
1916
import { debug, error } from "./logger.js";
2017

21-
// TODO: Remove this, temporary only to run some tests
22-
const getDerivedTags = (tags: string[]) => tags;
23-
2418
interface CachedFetchValue {
2519
kind: "FETCH";
2620
data: {
@@ -146,7 +140,7 @@ export default class S3Cache {
146140
const { Body, LastModified } = await this.getS3Object(key, "fetch", keys);
147141
const lastModified = await this.getHasRevalidatedTags(
148142
key,
149-
LastModified?.getTime(),
143+
LastModified?.getTime()
150144
);
151145
if (lastModified === -1) {
152146
// If some tags are stale we need to force revalidation
@@ -167,7 +161,7 @@ export default class S3Cache {
167161

168162
async getIncrementalCache(
169163
key: string,
170-
keys: string[],
164+
keys: string[]
171165
): Promise<CacheHandlerValue | null> {
172166
if (keys.includes(this.buildS3Key(key, "body"))) {
173167
debug("get body cache ", { key });
@@ -209,7 +203,7 @@ export default class S3Cache {
209203
]);
210204
const lastModified = await this.getHasRevalidatedTags(
211205
key,
212-
LastModified?.getTime(),
206+
LastModified?.getTime()
213207
);
214208
if (lastModified === -1) {
215209
// If some tags are stale we need to force revalidation
@@ -242,7 +236,7 @@ export default class S3Cache {
242236
const { Body, LastModified } = await this.getS3Object(
243237
key,
244238
"redirect",
245-
keys,
239+
keys
246240
);
247241
return {
248242
lastModified: LastModified?.getTime(),
@@ -276,15 +270,15 @@ export default class S3Cache {
276270
metaPromise = this.putS3Object(
277271
key,
278272
"meta",
279-
JSON.stringify({ status: data.status, headers: data.headers }),
273+
JSON.stringify({ status: data.status, headers: data.headers })
280274
);
281275
}
282276
await Promise.all([
283277
this.putS3Object(key, "html", html),
284278
this.putS3Object(
285279
key,
286280
isAppPath ? "rsc" : "json",
287-
isAppPath ? pageData : JSON.stringify(pageData),
281+
isAppPath ? pageData : JSON.stringify(pageData)
288282
),
289283
metaPromise,
290284
]);
@@ -297,13 +291,13 @@ export default class S3Cache {
297291
} else if (data === null || data === undefined) {
298292
await this.deleteS3Objects(key);
299293
}
300-
// Write getDerivedTags to dynamodb
294+
// Write derivedTags to dynamodb
301295
// If we use an in house version of getDerivedTags in build we should use it here instead of next's one
302296
const derivedTags: string[] =
303297
data?.kind === "FETCH"
304-
? getDerivedTags(data.data.tags ?? [])
298+
? data.data.tags ?? []
305299
: data?.kind === "PAGE"
306-
? getDerivedTags(data.headers?.["x-next-cache-tags"]?.split(",") ?? [])
300+
? data.headers?.["x-next-cache-tags"]?.split(",") ?? []
307301
: [];
308302
debug("derivedTags", derivedTags);
309303
// Get all tags stored in dynamodb for the given key
@@ -315,7 +309,7 @@ export default class S3Cache {
315309
tagsToWrite.map((tag) => ({
316310
path: key,
317311
tag: tag,
318-
})),
312+
}))
319313
);
320314
}
321315
}
@@ -333,7 +327,7 @@ export default class S3Cache {
333327
paths?.map((path) => ({
334328
path: path,
335329
tag: tag,
336-
})) ?? [],
330+
})) ?? []
337331
);
338332
}
339333

@@ -353,7 +347,7 @@ export default class S3Cache {
353347
ExpressionAttributeValues: {
354348
":key": { S: this.buildDynamoKey(path) },
355349
},
356-
}),
350+
})
357351
);
358352
const tags = result.Items?.map((item) => item.tag.S ?? "") ?? [];
359353
debug("tags for path", path, tags);
@@ -382,7 +376,7 @@ export default class S3Cache {
382376
":key": { S: this.buildDynamoKey(key) },
383377
":lastModified": { N: String(lastModified ?? 0) },
384378
},
385-
}),
379+
})
386380
);
387381
const revalidatedTags = result.Items ?? [];
388382
debug("revalidatedTags", revalidatedTags);
@@ -407,12 +401,12 @@ export default class S3Cache {
407401
ExpressionAttributeValues: {
408402
":tag": { S: this.buildDynamoKey(tag) },
409403
},
410-
}),
404+
})
411405
);
412406
return (
413407
// We need to remove the buildId from the path
414408
Items?.map(
415-
({ path: { S: key } }) => key?.replace(`${this.buildId}/`, "") ?? "",
409+
({ path: { S: key } }) => key?.replace(`${this.buildId}/`, "") ?? ""
416410
) ?? []
417411
);
418412
} catch (e) {
@@ -437,9 +431,9 @@ export default class S3Cache {
437431
},
438432
})),
439433
},
440-
}),
434+
})
441435
);
442-
}),
436+
})
443437
);
444438
} catch (e) {
445439
error("Failed to batch write dynamo item", e);
@@ -475,7 +469,7 @@ export default class S3Cache {
475469
CACHE_BUCKET_KEY_PREFIX ?? "",
476470
extension === "fetch" ? "__fetch" : "",
477471
this.buildId,
478-
extension === "fetch" ? key : `${key}.${extension}`,
472+
extension === "fetch" ? key : `${key}.${extension}`
479473
);
480474
}
481475

@@ -490,7 +484,7 @@ export default class S3Cache {
490484
// add a point to the key so that it only matches the key and
491485
// not other keys starting with the same string
492486
Prefix: `${this.buildS3KeyPrefix(key)}.`,
493-
}),
487+
})
494488
);
495489
return (Contents ?? []).map(({ Key }) => Key) as string[];
496490
}
@@ -503,7 +497,7 @@ export default class S3Cache {
503497
new GetObjectCommand({
504498
Bucket: CACHE_BUCKET_NAME,
505499
Key: this.buildS3Key(key, extension),
506-
}),
500+
})
507501
);
508502
return result;
509503
} catch (e) {
@@ -515,22 +509,22 @@ export default class S3Cache {
515509
private putS3Object(
516510
key: string,
517511
extension: Extension,
518-
value: PutObjectCommandInput["Body"],
512+
value: PutObjectCommandInput["Body"]
519513
) {
520514
return this.client.send(
521515
new PutObjectCommand({
522516
Bucket: CACHE_BUCKET_NAME,
523517
Key: this.buildS3Key(key, extension),
524518
Body: value,
525-
}),
519+
})
526520
);
527521
}
528522

529523
private async deleteS3Objects(key: string) {
530524
try {
531525
const regex = new RegExp(`\.(json|rsc|html|body|meta|fetch|redirect)$`);
532526
const s3Keys = (await this.listS3Object(key)).filter(
533-
(key) => key && regex.test(key),
527+
(key) => key && regex.test(key)
534528
);
535529

536530
await this.client.send(
@@ -539,7 +533,7 @@ export default class S3Cache {
539533
Delete: {
540534
Objects: s3Keys.map((Key) => ({ Key })),
541535
},
542-
}),
536+
})
543537
);
544538
} catch (e) {
545539
error("Failed to delete cache", e);

0 commit comments

Comments
 (0)