Skip to content

Commit 9890bca

Browse files
夏一飞夏一飞
authored andcommitted
refactor: remove redundant ensureUserTableExists calls
1 parent c4a2d9b commit 9890bca

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

app/api/users/route.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { NextRequest, NextResponse } from "next/server";
22
import { query } from "@/lib/db/client";
3+
import { ensureUserTableExists } from "@/lib/db/users";
34

45
export async function GET(req: NextRequest) {
56
try {
7+
// 确保表结构正确
8+
await ensureUserTableExists();
9+
610
const { searchParams } = new URL(req.url);
711
const page = parseInt(searchParams.get("page") || "1");
812
const pageSize = parseInt(searchParams.get("pageSize") || "20");

lib/db/users.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ async function ensureDeletedColumnExists() {
134134
}
135135

136136
export async function deleteUser(userId: string) {
137-
await ensureUserTableExists();
138137
await ensureDeletedColumnExists();
139138

140139
const updateResult = await query(
@@ -163,7 +162,6 @@ export async function getUsers({
163162
sortOrder = null,
164163
search = null,
165164
}: GetUsersOptions = {}) {
166-
await ensureUserTableExists();
167165
await ensureDeletedColumnExists();
168166

169167
const offset = (page - 1) * pageSize;
@@ -221,9 +219,6 @@ export async function getUsers({
221219
}
222220

223221
export async function getAllUsers(includeDeleted: boolean = false) {
224-
await ensureUserTableExists();
225-
await ensureDeletedColumnExists();
226-
227222
const whereClause = includeDeleted
228223
? ""
229224
: "WHERE (deleted = FALSE OR deleted IS NULL)";

0 commit comments

Comments
 (0)