Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Delete Upstash Search index instead of resetting documents

Rafi06cdca8ca785
diff --git a/apps/web/lib/api/partners/search/providers/upstash-search.ts b/apps/web/lib/api/partners/search/providers/upstash-search.ts
index 5f036dfeb1..0fac4baae5 100644
--- a/apps/web/lib/api/partners/search/providers/upstash-search.ts
+++ b/apps/web/lib/api/partners/search/providers/upstash-search.ts
@@ -62,7 +62,7 @@ interface UpstashSearchIndexClient {
): Promise<string>;
delete(documentIds: string[]): Promise<{ deleted: number }>;
info(): Promise<{ pendingDocumentCount: number; documentCount: number }>;
- reset(): Promise<string>;
+ deleteIndex(): Promise<string>;
}
interface CreateUpstashSearchPartnerSearchProviderOptions {
@@ -268,7 +268,7 @@ function logPartnerSearchDebug(details: Record<string, unknown>) {
console.log("[Partner Search Debug] Upstash Search", details);
}
-export async function resetUpstashSearchPartnerSearchIndex({
+export async function deleteUpstashSearchPartnerSearchIndex({
searchIndex,
indexName,
}: CreateUpstashSearchPartnerSearchProviderOptions = {}) {
@@ -276,10 +276,10 @@ export async function resetUpstashSearchPartnerSearchIndex({
const index = searchIndex ?? createSearchIndex(resolvedIndexName);
const { documentCount } = await withTransientRetry(() => index.info());
- // Upstash Search reset clears the whole index in one operation. It is the
- // appropriate way to remove documents from an obsolete index shape before
- // a full backfill, instead of issuing one delete request per document.
- await withTransientRetry(() => index.reset());
+ // Delete the logical index instead of resetting its documents. The next
+ // backfill recreates the index automatically when it writes the first
+ // document.
+ await withTransientRetry(() => index.deleteIndex());
return { indexName: resolvedIndexName, documentCount };
}
diff --git a/apps/web/scripts/partners/delete-partner-search-index.ts b/apps/web/scripts/partners/delete-partner-search-index.ts
index 061c1e1792..1793bc56d9 100644
--- a/apps/web/scripts/partners/delete-partner-search-index.ts
+++ b/apps/web/scripts/partners/delete-partner-search-index.ts
@@ -1,6 +1,6 @@
import {
+ deleteUpstashSearchPartnerSearchIndex,
getPartnerSearchProviderName,
- resetUpstashSearchPartnerSearchIndex,
} from "@/lib/api/partners/search";
import { chunk } from "@dub/utils";
import { Redis } from "@upstash/redis";
@@ -106,7 +106,7 @@ async function main() {
}
if (providerName === "upstash-search") {
- const { documentCount } = await resetUpstashSearchPartnerSearchIndex({
+ const { documentCount } = await deleteUpstashSearchPartnerSearchIndex({
indexName,
});
console.log(
diff --git a/apps/web/tests/partners/upstash-search-partner-search-provider.test.ts b/apps/web/tests/partners/upstash-search-partner-search-provider.test.ts
index c420aed499..553ba6fca7 100644
--- a/apps/web/tests/partners/upstash-search-partner-search-provider.test.ts
+++ b/apps/web/tests/partners/upstash-search-partner-search-provider.test.ts
@@ -1,6 +1,6 @@
import {
createUpstashSearchPartnerSearchProvider,
- resetUpstashSearchPartnerSearchIndex,
+ deleteUpstashSearchPartnerSearchIndex,
type PartnerSearchDocument,
} from "@/lib/api/partners/search";
import { beforeEach, describe, expect, it, vi } from "vitest";
@@ -23,8 +23,8 @@ const document: PartnerSearchDocument = {
const mocks = vi.hoisted(() => ({
delete: vi.fn(),
+ deleteIndex: vi.fn(),
info: vi.fn(),
- reset: vi.fn(),
search: vi.fn(),
upsert: vi.fn(),
}));
@@ -32,8 +32,8 @@ const mocks = vi.hoisted(() => ({
function createSearchIndexMock() {
return {
delete: mocks.delete,
+ deleteIndex: mocks.deleteIndex,
info: mocks.info,
- reset: mocks.reset,
search: mocks.search,
upsert: mocks.upsert,
};
@@ -74,7 +74,7 @@ describe("Upstash Search partner search provider", () => {
documentCount: 0,
pendingDocumentCount: 0,
});
- mocks.reset.mockResolvedValue("Success");
+ mocks.deleteIndex.mockResolvedValue("Success");
mocks.search.mockResolvedValue([]);
mocks.upsert.mockResolvedValue("Success");
});
@@ -202,14 +202,14 @@ describe("Upstash Search partner search provider", () => {
}
});
- it("resets every document in the index in one operation", async () => {
+ it("deletes the logical index in one operation", async () => {
mocks.info.mockResolvedValue({
documentCount: 100_005,
pendingDocumentCount: 0,
});
await expect(
- resetUpstashSearchPartnerSearchIndex({
+ deleteUpstashSearchPartnerSearchIndex({
searchIndex: createSearchIndexMock(),
indexName: "test-index",
}),
@@ -217,6 +217,6 @@ describe("Upstash Search partner search provider", () => {
indexName: "test-index",
documentCount: 100_005,
});
- expect(mocks.reset).toHaveBeenCalledOnce();
+ expect(mocks.deleteIndex).toHaveBeenCalledOnce();
});
});