Skip to content

Kernel API transferBlockRef #8522

Closed
Closed
@frostime

Description

@frostime
Contributor

In what scenarios do you need this feature?

目前思源支持「转移引用」这个功能,可以把一个块的全部引用全都转移到另一个块上面。

但是有些时候更加细粒度的转移也是有必要的,比如我希望整理一个大主题的双链,把他们拆分到一些更小的主题中。所以我计划开发一个增强转移ref的插件,可以将部分引用转移到别的块上。

目前我遇到的问题是找不到合适而安全的方法去完成「转移引用」这个功能。因此希望 D 可以提供一个类似 transfer ref 但是功能上更加细粒度的 API。

Describe the optimal solution

期望的 API行为:给定引用了 fromID 的块ID 集合 refIDs ,通过这个 API 可以把 refIDs 们引用的目标转移到 toID

  • fromID: 原先被引用的块的 ID
  • refIDs: 引用了 fromID 的块
  • toID: 转移引用的目标

我看了一下源代码觉得是可以实现的,TransferBlockRef 函数的实现就是先使用 SQL 查询 fromID 所有的引用,然后通过 for 循环把这些引用转移到别的 ID 上

refIDs, _ := sql.QueryRefIDsByDefID(fromID, false)
for _, refID := range refIDs {
    //....
}

那么只要把 refIDs, _ := sql.QueryRefIDsByDefID(fromID, false) 这一行去掉,换成传入的参数,就可以实现部分转移的功能了。

image

Describe the candidate solution

No response

Other information

No response

Activity

88250

88250 commented on Jun 12, 2023

@88250
Member

应该能提供,我想问下这个场景里面参数 refIDs 是从哪里来的。

frostime

frostime commented on Jun 12, 2023

@frostime
ContributorAuthor

应该能提供,我想问下这个场景里面参数 refIDs 是从哪里来的。

我自己先用 SQL API 读取 refs 表来获取所有的 refIDs

读取了所有 refID 后,显示在一个 GUI 面板里,让用户自己批量选择一个子集,然后指定转移到另一个块ID上。

changed the title [-]API请求: 更加细粒度的 TransferRef[/-] [+]Kernel API `transferRefs`[/+] on Jun 13, 2023
self-assigned this
on Jun 13, 2023
changed the title [-]Kernel API `transferRefs`[/-] [+]Kernel API `transferBlockRef`[/+] on Jun 13, 2023
added this to the 2.9.1 milestone on Jun 13, 2023
added a commit that references this issue on Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @88250@frostime

      Issue actions

        Kernel API `transferBlockRef` · Issue #8522 · siyuan-note/siyuan