Skip to content

Commit

Permalink
更新版本为 0.0.6
Browse files Browse the repository at this point in the history
数据库查询的文档也设置子文档数量。
优化数据库查询时引用数量的获取。
  • Loading branch information
Misuzu2027 committed Oct 7, 2024
1 parent 4762f8d commit dfc6539
Show file tree
Hide file tree
Showing 10 changed files with 280 additions and 49 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

该插件使用两种搜索方式,一种是“数据库查询”,另一种是“根据路径获取文档接口”;

因为数据库不存在文档的子文档数量、文档大小、文档顺序 信息,所以在使用数据库查询时,使用了前面提到的排序方式,会重置为设置中的:“数据库默认查询方式”。
因为数据库不存在 子文档数量、文档大小、文档顺序 信息,所以在使用数据库查询时,使用了前面提到的排序方式,会重置为设置中的:“数据库默认查询方式”。
v0.0.6 支持子文档数量排序,通过 `/api/filetree/listDocTree` 接口获取,不过是查询完数据库后再查询接口排序,所以在查询全部文档没有返回所有文档时(设置的限制大小小于所有文档),此排序不准确。


#### 何时使用数据库查询?
Expand Down
3 changes: 2 additions & 1 deletion README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

该插件使用两种搜索方式,一种是“数据库查询”,另一种是“根据路径获取文档接口”;

因为数据库不存在文档的子文档数量、文档大小、文档顺序 信息,所以在使用数据库查询时,使用了前面提到的排序方式,会重置为设置中的:“数据库默认查询方式”。
因为数据库不存在 子文档数量、文档大小、文档顺序 信息,所以在使用数据库查询时,使用了前面提到的排序方式,会重置为设置中的:“数据库默认查询方式”。
v0.0.6 支持子文档数量排序,通过 `/api/filetree/listDocTree` 接口获取,不过是查询完数据库后再查询接口排序,所以在查询全部文档没有返回所有文档时(设置的限制大小小于所有文档),此排序不准确。


#### 何时使用数据库查询?
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "syplugin-dual-doc-list",
"author": "Misuzu2027",
"url": "https://github.com/Misuzu2027/syplugin-dual-doc-list",
"version": "0.0.5",
"version": "0.0.6",
"minAppVersion": "3.0.12",
"backends": [
"all"
Expand Down
14 changes: 8 additions & 6 deletions src/components/doc-list/doc-list.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,10 @@
curPathNotebookId = null;
curPathDocId = null;
curPathDocPath = null;
curPathSortMethod =
SettingService.ins.SettingConfig.defaultDbQuerySortOrder;
if (!lockSortOrder) {
curPathSortMethod =
SettingService.ins.SettingConfig.defaultDbQuerySortOrder;
}
updateDocList(
curPathNotebookId,
curPathDocId,
Expand Down Expand Up @@ -692,8 +694,8 @@
isStrBlank(docSortMethod) ||
docSortMethod.startsWith("Custom") ||
docSortMethod.startsWith("Size") ||
docSortMethod.startsWith("SubDoc") ||
docSortMethod.startsWith("FileTree")
// || (docSortMethod.startsWith("SubDoc") && isStrBlank(notebookId))
) {
docSortMethod =
SettingService.ins.SettingConfig.defaultDbQuerySortOrder;
Expand All @@ -704,6 +706,7 @@
await queryDocumentByDb(
notebookId,
parentDocId,
docPath,
keywords,
showSubDocuments,
fullTextSearch,
Expand Down Expand Up @@ -748,8 +751,7 @@
let iconHtml = `<span class="box-path__icon">${icon}</span>`;
let nameHtml = `<span class="doc-path" data-path-type="box" data-id="${box}"> ${notebook.name}</span>`;
let boxPathHtml = iconHtml + nameHtml;
// let name = notebook.name;
console.log(box);
return boxPathHtml;
}
Expand Down Expand Up @@ -1092,7 +1094,7 @@
>
<li
data-node-id={item.fileBlock.id}
data-name={escapeAttr(item.fileBlock.name)}
data-block-name={escapeAttr(item.fileBlock.name)}
data-count={item.fileBlock.subFileCount}
data-type="navigation-file"
style="--file-toggle-width:40px;height:32px;padding:2px 5px;"
Expand Down
38 changes: 36 additions & 2 deletions src/service/search/search-sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ export function generateDocumentListSql(
let includeNotebookIds = queryCriteria.includeNotebookIds;
let documentSortMethod = queryCriteria.documentSortMethod;
let includeConcatFields = queryCriteria.includeConcatFields;
let columns: string[] = [" * ",
` (SELECT count(1) FROM refs WHERE def_block_root_id = blocks.id) refCount `,
let columns: string[] = [
// " * "
" id, root_id, box, path, hpath, name, alias, memo, tag, content, ial, created, updated ",

// 子文档数量查询sql,太影响性能了
// ` ( SELECT count( 1 ) FROM blocks sub WHERE type = 'd' AND path = REPLACE(blocks.path,'.sy','/') || id || '.sy' ) subDocCount `
];
Expand Down Expand Up @@ -71,13 +73,17 @@ export function generateDocumentListSql(
} else if (documentSortMethod == 'CreatedDESC') {
orders.push([" created DESC "]);
} else if (documentSortMethod == 'RefCountASC') {
columns.push(` (SELECT count(1) FROM refs WHERE def_block_root_id = blocks.id) refCount `);
orders.push([" refCount ASC ", " updated DESC "]);
} else if (documentSortMethod == 'RefCountDESC') {
columns.push(` (SELECT count(1) FROM refs WHERE def_block_root_id = blocks.id) refCount `);
orders.push([" refCount DESC ", " updated DESC "]);
} else if (documentSortMethod == 'NameASC') {
orders.push([" content ASC "]);
} else if (documentSortMethod == 'NameDESC') {
orders.push([" content DESC "]);
} else {
orders.push([" updated DESC "]);
}

let columnSql = columns.join(" , ");
Expand Down Expand Up @@ -106,6 +112,34 @@ export function generateDocumentListSql(



export function generateGetRootBlockCountSql(
rootIds: string[],
): string {


let columns: string[] = [" def_block_root_id ", "count(1) count"];


let defBlockRootIdIn = " "
if (isArrayNotEmpty(rootIds)) {
defBlockRootIdIn = generateAndInConditions("def_block_root_id", rootIds);

}

let columnSql = columns.join(" , ");
let basicSql = `
SELECT
${columnSql}
FROM refs
WHERE 1 = 1
${defBlockRootIdIn}
GROUP BY def_block_root_id
`

return cleanSpaceText(basicSql);
}




function generateDocumentIdContentTableSql(
Expand Down
Loading

0 comments on commit dfc6539

Please sign in to comment.