From 17d8c79057a3ce597917a984970f9d33e5593083 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sun, 4 Jun 2023 09:35:48 +0800 Subject: [PATCH] :art: Support for opening file history on the doc tree https://github.com/siyuan-note/siyuan/issues/8448 --- app/src/history/doc.ts | 2 +- kernel/model/history.go | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/src/history/doc.ts b/app/src/history/doc.ts index 1a2957b33..3184ef514 100644 --- a/app/src/history/doc.ts +++ b/app/src/history/doc.ts @@ -139,7 +139,7 @@ export const openDocHistory = (options: { event.preventDefault(); break; } else if (target.classList.contains("b3-list-item") && !isLoading) { - getHistoryPath(target, opElement.value, options.notebookId, (dataPath) => { + getHistoryPath(target, opElement.value, options.id, (dataPath) => { fetchPost("/api/history/getDocHistoryContent", { historyPath: dataPath, }, (response) => { diff --git a/kernel/model/history.go b/kernel/model/history.go index fa6532f5f..85c7ba4d4 100644 --- a/kernel/model/history.go +++ b/kernel/model/history.go @@ -311,20 +311,21 @@ type HistoryItem struct { Path string `json:"path"` } +const fileHistoryPageSize = 32 + func FullTextSearchHistory(query, box, op string, typ, page int) (ret []string, pageCount, totalCount int) { query = gulu.Str.RemoveInvisible(query) if "" != query && HistoryTypeDocID != typ { query = stringQuery(query) } - pageSize := 32 - offset := (page - 1) * pageSize + offset := (page - 1) * fileHistoryPageSize table := "histories_fts_case_insensitive" stmt := "SELECT DISTINCT created FROM " + table + " WHERE " stmt += buildSearchHistoryQueryFilter(query, op, box, table, typ) countStmt := strings.ReplaceAll(stmt, "SELECT DISTINCT created", "SELECT COUNT(DISTINCT created) AS total") - stmt += " ORDER BY created DESC LIMIT " + strconv.Itoa(pageSize) + " OFFSET " + strconv.Itoa(offset) + stmt += " ORDER BY created DESC LIMIT " + strconv.Itoa(fileHistoryPageSize) + " OFFSET " + strconv.Itoa(offset) result, err := sql.QueryHistory(stmt) if nil != err { return @@ -343,20 +344,20 @@ func FullTextSearchHistory(query, box, op string, typ, page int) (ret []string, return } totalCount = int(result[0]["total"].(int64)) - pageCount = int(math.Ceil(float64(totalCount) / float64(pageSize))) + pageCount = int(math.Ceil(float64(totalCount) / float64(fileHistoryPageSize))) return } func FullTextSearchHistoryItems(created, query, box, op string, typ int) (ret []*HistoryItem) { query = gulu.Str.RemoveInvisible(query) - if "" != query { + if "" != query && HistoryTypeDocID != typ { query = stringQuery(query) } table := "histories_fts_case_insensitive" stmt := "SELECT * FROM " + table + " WHERE " stmt += buildSearchHistoryQueryFilter(query, op, box, table, typ) - stmt += " AND created = '" + created + "' ORDER BY created DESC LIMIT " + fmt.Sprintf("%d", Conf.Search.Limit) + stmt += " AND created = '" + created + "' ORDER BY created DESC LIMIT " + fmt.Sprintf("%d", fileHistoryPageSize) sqlHistories := sql.SelectHistoriesRawStmt(stmt) ret = fromSQLHistories(sqlHistories) return