Skip to content

Commit ebea5ed

Browse files
committed
fix flaky test
1 parent 49fcd0f commit ebea5ed

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

packages/cloudflare/src/api/d1-tag-cache.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -104,28 +104,24 @@ class D1TagCache implements TagCache {
104104
try {
105105
const uniqueTags = new Set<string>();
106106
const results = await db.batch(
107-
tags.reduce<D1PreparedStatement[]>((acc, { tag, path, revalidatedAt }) => {
108-
if (revalidatedAt === 1) {
109-
// new tag/path mapping from set
110-
acc.push(
111-
db
107+
tags
108+
.map(({ tag, path, revalidatedAt }) => {
109+
if (revalidatedAt === 1) {
110+
// new tag/path mapping from set
111+
return db
112112
.prepare(`INSERT INTO ${table.tags} (tag, path) VALUES (?, ?)`)
113-
.bind(this.getCacheKey(tag), this.getCacheKey(path))
114-
);
115-
}
116-
117-
if (!uniqueTags.has(tag) && revalidatedAt !== -1) {
118-
// tag was revalidated
119-
uniqueTags.add(tag);
120-
acc.push(
121-
db
122-
.prepare(`INSERT INTO ${table.revalidations} (tag, revalidatedAt) VALUES (?, ?)`)
123-
.bind(this.getCacheKey(tag), revalidatedAt ?? Date.now())
124-
);
125-
}
113+
.bind(this.getCacheKey(tag), this.getCacheKey(path));
114+
}
126115

127-
return acc;
128-
}, [])
116+
if (!uniqueTags.has(tag) && revalidatedAt !== -1) {
117+
// tag was revalidated
118+
uniqueTags.add(tag);
119+
return db
120+
.prepare(`INSERT INTO ${table.revalidations} (tag, revalidatedAt) VALUES (?, ?)`)
121+
.bind(this.getCacheKey(tag), revalidatedAt ?? Date.now());
122+
}
123+
})
124+
.filter((stmt) => !!stmt)
129125
);
130126

131127
const failedResults = results.filter((res) => !res.success);

0 commit comments

Comments
 (0)