Commit 7c5bc957 authored by Chunchi Che's avatar Chunchi Che

optimize sqlite middleware and ready for deck page

parent 9ef609d1
Pipeline #22872 passed with stages
in 17 minutes and 5 seconds
......@@ -29,8 +29,9 @@ export interface sqliteAction {
};
// 需要读取卡牌数据的ID
payload?: {
id?: number;
query?: string;
id?: number; // 卡牌ID
query?: string; // 用于全文检索的query
type?: number; // 通过`type`过滤
};
}
......@@ -85,7 +86,9 @@ export default async function (action: sqliteAction): Promise<sqliteResult> {
}
case sqliteCmd.FTS: {
if (YGODB && action.payload && action.payload.query) {
// TODO: 这里应该可以优化为联表查询
const query = action.payload.query;
const type = action.payload.type;
const ftsTexts: CardText[] = [];
const ftsMetas: CardMeta[] = [];
......@@ -101,10 +104,18 @@ export default async function (action: sqliteAction): Promise<sqliteResult> {
for (const text of ftsTexts) {
const id = text.id;
if (id) {
const dataStmt = YGODB.prepare(
"SELECT * FROM datas WHERE ID = $id"
);
if (id && type !== undefined) {
const sql = "SELECT * FROM datas WHERE ID = $id AND type = $type";
const dataStmt = YGODB.prepare(sql);
const data: CardData = dataStmt.getAsObject({
$id: id,
$type: type,
});
ftsMetas.push({ id, data, text });
} else if (id) {
const sql = "SELECT * FROM datas WHERE ID = $id";
const dataStmt = YGODB.prepare(sql);
const data: CardData = dataStmt.getAsObject({ $id: id });
ftsMetas.push({ id, data, text });
......
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