Skip to content

Commit

Permalink
[opt] Bullet Retrieval performance is improved by an estimated 200x
Browse files Browse the repository at this point in the history
  • Loading branch information
AILHC committed Mar 20, 2024
1 parent 1e63ac6 commit 2cd3063
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions src/periodic/Bullet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import type { TableResult } from 'obsidian-dataview/lib/api/plugin-api';
import { PluginSettings } from '../type';

import { Markdown } from '../component/Markdown';
import { DataviewApi } from 'obsidian-dataview';
import { DataArray, DataviewApi, Link } from 'obsidian-dataview';

import { File } from '../periodic/File';
import { ERROR_MESSAGE } from '../constant';
import { renderError } from '../util';
import { I18N_MAP } from '../i18n';
import { SListItem } from 'obsidian-dataview/lib/data-model/serialized/markdown';

export class Bullet {
app: App;
Expand Down Expand Up @@ -62,25 +63,29 @@ export class Bullet {
}`;
})
.join(' ');
const result = (await this.dataview.tryQuery(
`
TABLE WITHOUT ID rows.L.text AS "Bullet", rows.L.link AS "Link"
FROM (${from}) AND -"${periodicNotesPath}/Templates"
FLATTEN file.lists AS L
WHERE ${where} AND !L.task AND file.path != "${filepath}"
GROUP BY file.link
SORT rows.file.link DESC
`
)) as TableResult;

this.dataview.table(
result.headers,
result.values,
div,
component,
filepath
);

// console.time("子弹检索1笔记耗时");
let lists: DataArray<SListItem> = await this.dataview.pages(`(${from}) and -"${periodicNotesPath}/Templates"`).file.lists;
let resultNew = lists.where(
(L) => {
let includeTag = false;
if (L.task || L.path === filepath) return false;
for (let tag of tags) {
includeTag = L.tags.includes(`#${tag}`);
if (includeTag) {
break;
}

}
// console.log(`file:${L.path},text:${L.text}`)
return includeTag;
});
let groupResult = resultNew.groupBy((elem) => {
return elem.link;
})
let sortResult = groupResult.sort((elem) => elem.rows.link as Link)
let tableResult =sortResult.map(k => [k.rows.text as string, k.rows.link as Link])
let tableValues = tableResult.array();
this.dataview.table(["Bullet", "Link"], tableValues, div, component, filepath);
ctx.addChild(component);
};
}

0 comments on commit 2cd3063

Please sign in to comment.