Skip to content

Commit

Permalink
修复 /api/files/token 返回慢的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lifegpc committed Dec 10, 2023
1 parent 4835818 commit 788606a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ const FILE_TABLE = `CREATE TABLE file (
height INT,
is_original BOOLEAN
);`;
const FILE_INDEX = `CREATE INDEX file_token ON file (token);`;
const FILEMETA_TABLE = `CREATE TABLE filemeta (
token TEXT,
is_nsfw BOOLEAN,
Expand Down Expand Up @@ -272,7 +273,7 @@ export class EhDb {
#lock_file: string | undefined;
#dblock_file: string | undefined;
#_tags: Map<string, number> | undefined;
readonly version = parse_ver("1.0.0-9");
readonly version = parse_ver("1.0.0-10");
constructor(base_path: string) {
const db_path = join(base_path, "data.db");
sure_dir_sync(base_path);
Expand Down Expand Up @@ -407,6 +408,9 @@ export class EhDb {
this.db.execute("ALTER TABLE token ADD secure BOOLEAN;");
this.db.execute("UPDATE token SET http_only = 1, secure = 0;");
}
if (compare_ver(v, parse_ver("1.0.0-10")) === -1) {
this.db.execute(FILE_INDEX);
}
this.#write_version();
if (need_optimize) this.optimize();
}
Expand Down Expand Up @@ -438,6 +442,7 @@ export class EhDb {
}
if (!this.#exist_table.has("file")) {
this.db.execute(FILE_TABLE);
this.db.execute(FILE_INDEX);
}
if (!this.#exist_table.has("filemeta")) {
this.db.execute(FILEMETA_TABLE);
Expand Down

0 comments on commit 788606a

Please sign in to comment.