Commit a6b1f93d authored by timel's avatar timel

optimize: invokeFts

parent 5e0baeb2
Pipeline #23055 passed with stages
in 13 minutes and 46 seconds
......@@ -23,34 +23,24 @@ export interface FtsParams {
export function invokeFts(db: Database, params: FtsParams): CardMeta[] {
const { query, conditions } = params;
const ftsTexts: CardText[] = [];
const ftsMetas: CardMeta[] = [];
const filterConditions = getFtsCondtions(conditions);
const textStmt = db.prepare(
`SELECT * FROM texts INNER JOIN datas ON texts.id = datas.id ${
filterConditions == ""
? "WHERE name LIKE $query"
: `WHERE name LIKE $query AND ${filterConditions}`
}`
);
textStmt.bind({ $query: `%${query}%` });
const stmt = db.prepare(`
SELECT datas.*, texts.*
FROM datas
INNER JOIN texts ON datas.id = texts.id
WHERE texts.name LIKE $query ${
filterConditions ? `AND ${filterConditions}` : ""
}
`);
while (textStmt.step()) {
const row = textStmt.getAsObject();
ftsTexts.push(row);
}
stmt.bind({ $query: `%${query}%` });
for (const text of ftsTexts) {
const id = text.id;
if (id) {
const sql = "SELECT * FROM datas WHERE ID = $id";
const dataStmt = db.prepare(sql);
const data: CardData = dataStmt.getAsObject({ $id: id });
if (Object.values(data).filter((v) => v !== undefined).length > 0) {
ftsMetas.push(constructCardMeta(id, data, text));
}
}
while (stmt.step()) {
const row = stmt.getAsObject() as CardData & CardText;
ftsMetas.push(constructCardMeta(row.id!, row, row));
}
return ftsMetas;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment