Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ Tables use snake_case naming:
- **CORS/Headers**: Requests to XMOJ mimic real browser headers for compatibility
- **Captcha**: Cloudflare Turnstile used for post/reply creation
- **Content Moderation**: AI model checks badge content for negative sentiment
- **Round Trips**: Workers often run far from the D1 primary (APAC), so each query costs tens of milliseconds while SQL itself takes well under one. Avoid per-item/N+1 queries in loops: fold N+1 lookups into one SQL statement, use `batch()` for independent statements, and `Promise.all` for independent fetches (bounded, when user input sets how many); keep loops where each query depends on the previous result, such as cursor pagination
- **Cron Jobs**: Daily cleanup of old read messages (5+ days) and expired sessions

### Language Note
Expand Down
4 changes: 2 additions & 2 deletions Source/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ export class Database {
}
}

public async Insert(Table: string, Data: object): Promise<Result> {
public async Insert(Table: string, Data: object, OrReplace: boolean = false): Promise<Result> {
if (readonly) {
return new Result(false, "数据库只读模式,无法写入");
}
let QueryString = "INSERT INTO `" + Table + "` (";
let QueryString = (OrReplace ? "INSERT OR REPLACE INTO `" : "INSERT INTO `") + Table + "` (";
for (let i in Data) {
QueryString += "`" + i + "`, ";
}
Expand Down
Loading
Loading