🎨 数据历史文档和资源文件支持分页和搜索 https://github.com/siyuan-note/siyuan/issues/4901

This commit is contained in:
Liang Ding 2022-08-23 10:06:58 +08:00
parent 9c4aac7096
commit 61f7f717f7
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
3 changed files with 34 additions and 1 deletions

View file

@ -38,7 +38,10 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
var db *sql.DB
var (
db *sql.DB
historyDB *sql.DB
)
func init() {
regex := func(re, s string) (bool, error) {
@ -141,6 +144,12 @@ func initDBTables() {
if nil != err {
logging.LogFatalf("create table [refs] failed: %s", err)
}
historyDB.Exec("DROP TABLE history_fts_case_insensitive")
_, err = db.Exec("CREATE VIRTUAL TABLE history_fts_case_insensitive USING fts5(type UNINDEXED, op UNINDEXED, title, content, created UNINDEXED, path UNINDEXED, tokenize=\"siyuan case_insensitive\")")
if nil != err {
logging.LogFatalf("create table [history_fts_case_insensitive] failed: %s", err)
}
}
func IndexMode() {
@ -192,6 +201,27 @@ func initDBConnection() {
db.SetMaxIdleConns(20)
db.SetMaxOpenConns(20)
db.SetConnMaxLifetime(365 * 24 * time.Hour)
if nil != historyDB {
historyDB.Close()
}
dsn = util.HistoryDBPath + "?_journal_mode=OFF" +
"&_synchronous=OFF" +
"&_secure_delete=OFF" +
"&_cache_size=-20480" +
"&_page_size=8192" +
"&_busy_timeout=7000" +
"&_ignore_check_constraints=ON" +
"&_temp_store=MEMORY" +
"&_case_sensitive_like=OFF" +
"&_locking_mode=EXCLUSIVE"
historyDB, err = sql.Open("sqlite3_extended", dsn)
if nil != err {
logging.LogFatalf("create database failed: %s", err)
}
historyDB.SetMaxIdleConns(1)
historyDB.SetMaxOpenConns(1)
historyDB.SetConnMaxLifetime(365 * 24 * time.Hour)
}
func SetCaseSensitive(b bool) {

View file

@ -168,6 +168,7 @@ var (
LogPath string // 配置目录下的日志文件 siyuan.log 路径
DBName = "siyuan.db" // SQLite 数据库文件名
DBPath string // SQLite 数据库文件路径
HistoryDBPath string // SQLite 历史数据库文件路径
BlockTreePath string // 区块树文件路径
AppearancePath string // 配置目录下的外观目录 appearance/ 路径
ThemesPath string // 配置目录下的外观目录下的 themes/ 路径
@ -271,6 +272,7 @@ func initWorkspaceDir(workspaceArg string) {
os.Setenv("TEMP", osTmpDir)
os.Setenv("TMP", osTmpDir)
DBPath = filepath.Join(TempDir, DBName)
HistoryDBPath = filepath.Join(TempDir, "history.db")
BlockTreePath = filepath.Join(TempDir, "blocktree.msgpack")
}

View file

@ -51,6 +51,7 @@ func BootMobile(container, appDir, workspaceDir, nativeLibDir, privateDataDir, l
os.RemoveAll(filepath.Join(TempDir, "repo"))
os.Setenv("TMPDIR", osTmpDir)
DBPath = filepath.Join(TempDir, DBName)
HistoryDBPath = filepath.Join(TempDir, "history.db")
BlockTreePath = filepath.Join(TempDir, "blocktree.msgpack")
AndroidNativeLibDir = nativeLibDir
AndroidPrivateDataDir = privateDataDir