Skip to content

Commit 092c0d3

Browse files
committed
Fix a bug where importer created duplicate lists
1 parent 482fdb4 commit 092c0d3

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

src/pages/accounts.tsx

+17-19
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import { loginRequired } from "../login.ts";
4141
import {
4242
type Account,
4343
type AccountOwner,
44-
type List,
4544
type Post,
4645
type PostVisibility,
4746
accountOwners,
@@ -1026,24 +1025,23 @@ accounts.post("/:id/migrate/import", async (c) => {
10261025
const listNames = new Set(csv.map((row) => row[0].trim()));
10271026
const listIds: Record<string, string> = {};
10281027
for (const listName of listNames) {
1029-
const result = await db
1030-
.insert(lists)
1031-
.values({
1032-
id: crypto.randomUUID(),
1033-
title: listName,
1034-
accountOwnerId: accountOwner.id,
1035-
})
1036-
.onConflictDoNothing()
1037-
.returning();
1038-
let list: List | undefined;
1039-
if (result.length < 1) {
1040-
list = await db.query.lists.findFirst({
1041-
where: and(
1042-
eq(lists.accountOwnerId, accountOwner.id),
1043-
eq(lists.title, listName),
1044-
),
1045-
});
1046-
} else {
1028+
let list = await db.query.lists.findFirst({
1029+
where: and(
1030+
eq(lists.accountOwnerId, accountOwner.id),
1031+
eq(lists.title, listName),
1032+
),
1033+
});
1034+
if (list == null) {
1035+
const result = await db
1036+
.insert(lists)
1037+
.values({
1038+
id: crypto.randomUUID(),
1039+
title: listName,
1040+
accountOwnerId: accountOwner.id,
1041+
})
1042+
.onConflictDoNothing()
1043+
.returning();
1044+
if (result.length < 1) continue;
10471045
list = result[0];
10481046
}
10491047
if (list == null) continue;

0 commit comments

Comments
 (0)