mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 08:30:12 +01:00
🎨 Support for opening file history on the doc tree https://github.com/siyuan-note/siyuan/issues/8448
This commit is contained in:
parent
f99d9e19bc
commit
772c809e31
3 changed files with 20 additions and 7 deletions
|
|
@ -337,6 +337,8 @@ func FullTextSearchHistory(query, box, op string, typ, page int) (ret []string,
|
||||||
stmt += " AND op = '" + op + "'"
|
stmt += " AND op = '" + op + "'"
|
||||||
}
|
}
|
||||||
stmt += " AND path LIKE '%/" + box + "/%' AND path LIKE '%.sy'"
|
stmt += " AND path LIKE '%/" + box + "/%' AND path LIKE '%.sy'"
|
||||||
|
} else if HistoryTypeDocID == typ {
|
||||||
|
stmt += " AND id = '" + query + "'"
|
||||||
} else if HistoryTypeAsset == typ {
|
} else if HistoryTypeAsset == typ {
|
||||||
stmt += " AND path LIKE '%/assets/%'"
|
stmt += " AND path LIKE '%/assets/%'"
|
||||||
}
|
}
|
||||||
|
|
@ -387,6 +389,8 @@ func FullTextSearchHistoryItems(created, query, box, op string, typ int) (ret []
|
||||||
stmt += " AND op = '" + op + "'"
|
stmt += " AND op = '" + op + "'"
|
||||||
}
|
}
|
||||||
stmt += " AND path LIKE '%/" + box + "/%' AND path LIKE '%.sy'"
|
stmt += " AND path LIKE '%/" + box + "/%' AND path LIKE '%.sy'"
|
||||||
|
} else if HistoryTypeDocID == typ {
|
||||||
|
stmt += " AND id = '" + query + "'"
|
||||||
} else if HistoryTypeAsset == typ {
|
} else if HistoryTypeAsset == typ {
|
||||||
stmt += " AND path LIKE '%/assets/%'"
|
stmt += " AND path LIKE '%/assets/%'"
|
||||||
}
|
}
|
||||||
|
|
@ -592,9 +596,10 @@ func ReindexHistory() (err error) {
|
||||||
var validOps = []string{HistoryOpClean, HistoryOpUpdate, HistoryOpDelete, HistoryOpFormat, HistoryOpSync, HistoryOpReplace}
|
var validOps = []string{HistoryOpClean, HistoryOpUpdate, HistoryOpDelete, HistoryOpFormat, HistoryOpSync, HistoryOpReplace}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
HistoryTypeDocName = 0
|
HistoryTypeDocName = 0 // Search docs by doc name
|
||||||
HistoryTypeDoc = 1
|
HistoryTypeDoc = 1 // Search docs by doc name and content
|
||||||
HistoryTypeAsset = 2
|
HistoryTypeAsset = 2 // Search assets
|
||||||
|
HistoryTypeDocID = 3 // Search docs by doc id
|
||||||
)
|
)
|
||||||
|
|
||||||
func indexHistoryDir(name string, luteEngine *lute.Lute) {
|
func indexHistoryDir(name string, luteEngine *lute.Lute) {
|
||||||
|
|
@ -640,6 +645,7 @@ func indexHistoryDir(name string, luteEngine *lute.Lute) {
|
||||||
p := strings.TrimPrefix(doc, util.HistoryDir)
|
p := strings.TrimPrefix(doc, util.HistoryDir)
|
||||||
p = filepath.ToSlash(p[1:])
|
p = filepath.ToSlash(p[1:])
|
||||||
histories = append(histories, &sql.History{
|
histories = append(histories, &sql.History{
|
||||||
|
ID: tree.Root.ID,
|
||||||
Type: HistoryTypeDoc,
|
Type: HistoryTypeDoc,
|
||||||
Op: op,
|
Op: op,
|
||||||
Title: title,
|
Title: title,
|
||||||
|
|
@ -652,7 +658,12 @@ func indexHistoryDir(name string, luteEngine *lute.Lute) {
|
||||||
for _, asset := range assets {
|
for _, asset := range assets {
|
||||||
p := strings.TrimPrefix(asset, util.HistoryDir)
|
p := strings.TrimPrefix(asset, util.HistoryDir)
|
||||||
p = filepath.ToSlash(p[1:])
|
p = filepath.ToSlash(p[1:])
|
||||||
|
_, id := util.LastID(asset)
|
||||||
|
if !ast.IsNodeIDPattern(id) {
|
||||||
|
id = ""
|
||||||
|
}
|
||||||
histories = append(histories, &sql.History{
|
histories = append(histories, &sql.History{
|
||||||
|
ID: id,
|
||||||
Type: HistoryTypeAsset,
|
Type: HistoryTypeAsset,
|
||||||
Op: op,
|
Op: op,
|
||||||
Title: filepath.Base(asset),
|
Title: filepath.Base(asset),
|
||||||
|
|
|
||||||
|
|
@ -237,7 +237,7 @@ func initHistoryDBConnection() {
|
||||||
|
|
||||||
func initHistoryDBTables() {
|
func initHistoryDBTables() {
|
||||||
historyDB.Exec("DROP TABLE histories_fts_case_insensitive")
|
historyDB.Exec("DROP TABLE histories_fts_case_insensitive")
|
||||||
_, err := historyDB.Exec("CREATE VIRTUAL TABLE histories_fts_case_insensitive USING fts5(type UNINDEXED, op UNINDEXED, title, content, path UNINDEXED, created UNINDEXED, tokenize=\"siyuan case_insensitive\")")
|
_, err := historyDB.Exec("CREATE VIRTUAL TABLE histories_fts_case_insensitive USING fts5(id UNINDEXED, type UNINDEXED, op UNINDEXED, title, content, path UNINDEXED, created UNINDEXED, tokenize=\"siyuan case_insensitive\")")
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create table [histories_fts_case_insensitive] failed: %s", err)
|
logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create table [histories_fts_case_insensitive] failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type History struct {
|
type History struct {
|
||||||
|
ID string
|
||||||
Type int
|
Type int
|
||||||
Op string
|
Op string
|
||||||
Title string
|
Title string
|
||||||
|
|
@ -87,7 +88,7 @@ func SelectHistoriesRawStmt(stmt string) (ret []*History) {
|
||||||
|
|
||||||
func scanHistoryRows(rows *sql.Rows) (ret *History) {
|
func scanHistoryRows(rows *sql.Rows) (ret *History) {
|
||||||
var history History
|
var history History
|
||||||
if err := rows.Scan(&history.Type, &history.Op, &history.Title, &history.Content, &history.Path, &history.Created); nil != err {
|
if err := rows.Scan(&history.ID, &history.Type, &history.Op, &history.Title, &history.Content, &history.Path, &history.Created); nil != err {
|
||||||
logging.LogErrorf("query scan field failed: %s\n%s", err, logging.ShortStack())
|
logging.LogErrorf("query scan field failed: %s\n%s", err, logging.ShortStack())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -112,8 +113,8 @@ func deleteHistoriesByPathPrefix(tx *sql.Tx, pathPrefix string, context map[stri
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
HistoriesFTSCaseInsensitiveInsert = "INSERT INTO histories_fts_case_insensitive (type, op, title, content, path, created) VALUES %s"
|
HistoriesFTSCaseInsensitiveInsert = "INSERT INTO histories_fts_case_insensitive (id, type, op, title, content, path, created) VALUES %s"
|
||||||
HistoriesPlaceholder = "(?, ?, ?, ?, ?, ?)"
|
HistoriesPlaceholder = "(?, ?, ?, ?, ?, ?, ?)"
|
||||||
)
|
)
|
||||||
|
|
||||||
func insertHistories(tx *sql.Tx, histories []*History, context map[string]interface{}) (err error) {
|
func insertHistories(tx *sql.Tx, histories []*History, context map[string]interface{}) (err error) {
|
||||||
|
|
@ -146,6 +147,7 @@ func insertHistories0(tx *sql.Tx, bulk []*History, context map[string]interface{
|
||||||
valueArgs := make([]interface{}, 0, len(bulk)*strings.Count(HistoriesPlaceholder, "?"))
|
valueArgs := make([]interface{}, 0, len(bulk)*strings.Count(HistoriesPlaceholder, "?"))
|
||||||
for _, b := range bulk {
|
for _, b := range bulk {
|
||||||
valueStrings = append(valueStrings, HistoriesPlaceholder)
|
valueStrings = append(valueStrings, HistoriesPlaceholder)
|
||||||
|
valueArgs = append(valueArgs, b.ID)
|
||||||
valueArgs = append(valueArgs, b.Type)
|
valueArgs = append(valueArgs, b.Type)
|
||||||
valueArgs = append(valueArgs, b.Op)
|
valueArgs = append(valueArgs, b.Op)
|
||||||
valueArgs = append(valueArgs, b.Title)
|
valueArgs = append(valueArgs, b.Title)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue