Skip to content

Commit

Permalink
πŸ› fix(Query): id2blocks, ε—ζ•°ι‡ι™εˆΆ
Browse files Browse the repository at this point in the history
  • Loading branch information
frostime committed Jan 26, 2025
1 parent 737eac2 commit b5c3175
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sy-query-view",
"version": "1.0.3",
"version": "1.0.4",
"type": "module",
"description": "This is a sample plugin based on vite and svelte for Siyuan (https://b3log.org/siyuan). Created with siyuan-plugin-cli v2.4.5.",
"repository": "https://github.com/frostime/sy-query-view",
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": "sy-query-view",
"author": "frostime",
"url": "https://github.com/frostime/sy-query-view",
"version": "1.0.3",
"version": "1.0.4",
"minAppVersion": "3.1.14",
"backends": [
"windows",
Expand Down
6 changes: 3 additions & 3 deletions public/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* @name sy-query-view
* @author frostime
* @version 1.0.3
* @updated 2025-01-17T14:56:39.077Z
* @version 1.0.4
* @updated 2025-01-26T10:00:43.019Z
*/

declare module 'siyuan' {
Expand Down Expand Up @@ -188,7 +188,7 @@ declare const Query: {
* @returns Array of wrapped blocks
* @alias `id2block`
*/
getBlocksByIds: (...ids: BlockId[]) => Promise<IWrappedList<IWrappedBlock>>;
getBlocksByIds: (...ids: (BlockId | BlockId[])[]) => Promise<IWrappedList<IWrappedBlock>>;
/**
* Gets the current document's ID
* @param protyle - Protyle instance
Expand Down
10 changes: 6 additions & 4 deletions src/core/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Author : frostime
* @Date : 2024-12-01 22:34:55
* @FilePath : /src/core/query.ts
* @LastEditTime : 2025-01-14 14:32:34
* @LastEditTime : 2025-01-20 23:51:42
* @Description :
*/
import { IProtyle } from "siyuan";
Expand Down Expand Up @@ -65,7 +65,8 @@ function mergeBlocks(blocks: Block[], mode: 'leaf' | 'root' = 'leaf') {

async function getBlocksByIds(...ids: BlockId[]) {
let idList = ids.map((id) => `"${id}"`);
let sqlCode = `select * from blocks where id in (${idList.join(",")})`;
let N = ids.length;
let sqlCode = `select * from blocks where id in (${idList.join(",")}) limit ${N + 1}`;
let data = await sql(sqlCode);
return data;
}
Expand Down Expand Up @@ -364,8 +365,9 @@ const Query = {
* @returns Array of wrapped blocks
* @alias `id2block`
*/
getBlocksByIds: async (...ids: BlockId[]): Promise<IWrappedList<IWrappedBlock>> => {
let blocks = await getBlocksByIds(...ids);
getBlocksByIds: async (...ids: (BlockId | BlockId[])[]): Promise<IWrappedList<IWrappedBlock>> => {
let flattenedIds: BlockId[] = ids.flat() as BlockId[];
let blocks = await getBlocksByIds(...flattenedIds);
return Query.wrapBlocks(blocks) as IWrappedList<IWrappedBlock>;
},

Expand Down

0 comments on commit b5c3175

Please sign in to comment.