From be6380cbf7f3384d2da7dfdce18233def6b47fca Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Wed, 2 Nov 2022 20:01:07 +0800 Subject: [PATCH 1/3] =?UTF-8?q?:bug:=20=E6=95=B0=E6=8D=AE=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E6=AF=8F=E9=A1=B5=E6=9C=80=E5=90=8E=E4=B8=80=E6=9D=A1?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=97=B6=E9=97=B4=E5=BC=82=E5=B8=B8=20Fix=20?= =?UTF-8?q?https://github.com/siyuan-note/siyuan/issues/6455?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/history.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/kernel/model/history.go b/kernel/model/history.go index 78d735e6f..653ef894a 100644 --- a/kernel/model/history.go +++ b/kernel/model/history.go @@ -317,8 +317,7 @@ func FullTextSearchHistory(query, box, op string, typ, page int) (ret []*History } pageSize := 32 - from := (page - 1) * pageSize - to := page * pageSize + offset := (page - 1) * pageSize table := "histories_fts_case_insensitive" stmt := "SELECT * FROM " + table + " WHERE " @@ -341,7 +340,7 @@ func FullTextSearchHistory(query, box, op string, typ, page int) (ret []*History stmt += " AND path LIKE '%/assets/%'" } countStmt := strings.ReplaceAll(stmt, "SELECT *", "SELECT COUNT(*) AS total") - stmt += " ORDER BY created DESC LIMIT " + strconv.Itoa(from) + ", " + strconv.Itoa(to) + stmt += " ORDER BY created DESC LIMIT " + strconv.Itoa(pageSize) + " OFFSET " + strconv.Itoa(offset) sqlHistories := sql.SelectHistoriesRawStmt(stmt) ret = fromSQLHistories(sqlHistories) result, err := sql.QueryHistory(countStmt) @@ -660,12 +659,9 @@ func fromSQLHistories(sqlHistories []*sql.History) (ret []*History) { } var items []*HistoryItem - var tmpTime int64 + tmpTime, _ := strconv.ParseInt(sqlHistories[0].Created, 10, 64) for _, sqlHistory := range sqlHistories { unixSec, _ := strconv.ParseInt(sqlHistory.Created, 10, 64) - if 0 == tmpTime { - tmpTime = unixSec - } if tmpTime == unixSec { item := &HistoryItem{ Title: sqlHistory.Title, @@ -691,6 +687,7 @@ func fromSQLHistories(sqlHistories []*sql.History) (ret []*History) { items = []*HistoryItem{} items = append(items, item) } + tmpTime = unixSec } if 0 < len(items) { ret = append(ret, &History{ From 46cec73e2a37031c98d61def98cc05d0d38be675 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Wed, 2 Nov 2022 20:10:59 +0800 Subject: [PATCH 2/3] =?UTF-8?q?:art:=20=E5=BC=80=E6=BA=90=E4=BA=91?= =?UTF-8?q?=E7=AB=AF=E5=90=8C=E6=AD=A5=E6=9C=8D=E5=8A=A1=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=20https://github.com/siyuan-note/siyuan/issues/6445?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/go.mod | 2 +- kernel/go.sum | 6 ++---- kernel/model/repository.go | 2 +- kernel/model/sync.go | 25 +++---------------------- 4 files changed, 7 insertions(+), 28 deletions(-) diff --git a/kernel/go.mod b/kernel/go.mod index ab15c4f7a..409cebcb4 100644 --- a/kernel/go.mod +++ b/kernel/go.mod @@ -36,7 +36,7 @@ require ( github.com/panjf2000/ants/v2 v2.6.0 github.com/patrickmn/go-cache v2.1.0+incompatible github.com/radovskyb/watcher v1.0.7 - github.com/siyuan-note/dejavu v0.0.0-20221102102630-25556844ddab + github.com/siyuan-note/dejavu v0.0.0-20221102120909-ed9ad2509c64 github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da github.com/siyuan-note/filelock v0.0.0-20221007163134-7e64809023ef diff --git a/kernel/go.sum b/kernel/go.sum index 32093fa62..82305d8e3 100644 --- a/kernel/go.sum +++ b/kernel/go.sum @@ -353,10 +353,8 @@ github.com/shurcooL/reactions v0.0.0-20181006231557-f2e0b4ca5b82/go.mod h1:TCR1l github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYEDaXHZDBsXlPCDqdhQuJkuw4NOtaxYe3xii4= github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw= -github.com/siyuan-note/dejavu v0.0.0-20221102101918-9258bfd2c7ca h1:yxlwyy/GxuzIBhTadAxjXNGAJYc3yrTjX8Yqq1SlVg4= -github.com/siyuan-note/dejavu v0.0.0-20221102101918-9258bfd2c7ca/go.mod h1:+U86jfsvpacZBThE3Ouf/ZQ4EsB4jGPJsMO2iuRv0LQ= -github.com/siyuan-note/dejavu v0.0.0-20221102102630-25556844ddab h1:pQJRm7GFp7DS3kCqlGVLq5T1jnIVNwOytbkr1BjByvY= -github.com/siyuan-note/dejavu v0.0.0-20221102102630-25556844ddab/go.mod h1:+U86jfsvpacZBThE3Ouf/ZQ4EsB4jGPJsMO2iuRv0LQ= +github.com/siyuan-note/dejavu v0.0.0-20221102120909-ed9ad2509c64 h1:psY8hXz/t7cwqJFR+6+vebb5s3P1AzqfkaJ+gIQGLjw= +github.com/siyuan-note/dejavu v0.0.0-20221102120909-ed9ad2509c64/go.mod h1:+U86jfsvpacZBThE3Ouf/ZQ4EsB4jGPJsMO2iuRv0LQ= github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 h1:Bi7/7f29LW+Fm0cHc0J1NO1cZqyJwljSWVmfOqVZgaE= github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75/go.mod h1:H8fyqqAbp9XreANjeSbc72zEdFfKTXYN34tc1TjZwtw= github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da h1:/jNhl7LC+9BhkWvNxuJDdsNfA/2wvfuj9mqWx4CbV90= diff --git a/kernel/model/repository.go b/kernel/model/repository.go index ce536dc53..84da78951 100644 --- a/kernel/model/repository.go +++ b/kernel/model/repository.go @@ -1009,7 +1009,7 @@ func subscribeEvents() { } func buildCloudConf() (ret *cloud.Conf, err error) { - if !IsValidCloudDirName(Conf.Sync.CloudName) { + if !cloud.IsValidCloudDirName(Conf.Sync.CloudName) { logging.LogWarnf("invalid cloud repo name, rename it to [main]") Conf.Sync.CloudName = "main" Conf.Save() diff --git a/kernel/model/sync.go b/kernel/model/sync.go index f035e87ca..eb578ec88 100644 --- a/kernel/model/sync.go +++ b/kernel/model/sync.go @@ -25,7 +25,6 @@ import ( "strings" "sync" "time" - "unicode/utf8" "github.com/88250/gulu" "github.com/dustin/go-humanize" @@ -70,7 +69,7 @@ func BootSyncData() { util.IncBootProgress(3, "Syncing data from the cloud...") BootSyncSucc = 0 - if !IsSubscriber() || !Conf.Sync.Enabled || "" == Conf.Sync.CloudName || !IsValidCloudDirName(Conf.Sync.CloudName) { + if !IsSubscriber() || !Conf.Sync.Enabled || "" == Conf.Sync.CloudName || !cloud.IsValidCloudDirName(Conf.Sync.CloudName) { return } @@ -135,7 +134,7 @@ func SyncData(boot, exit, byHand bool) { return } - if !IsValidCloudDirName(Conf.Sync.CloudName) { + if !cloud.IsValidCloudDirName(Conf.Sync.CloudName) { return } @@ -297,7 +296,7 @@ func CreateCloudSyncDir(name string) (err error) { name = strings.TrimSpace(name) name = gulu.Str.RemoveInvisible(name) - if !IsValidCloudDirName(name) { + if !cloud.IsValidCloudDirName(name) { return errors.New(Conf.Language(37)) } @@ -405,24 +404,6 @@ func formatErrorMsg(err error) string { return msg } -func IsValidCloudDirName(cloudDirName string) bool { - if 16 < utf8.RuneCountInString(cloudDirName) || 1 > utf8.RuneCountInString(cloudDirName) { - return false - } - - chars := []byte{'~', '`', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '+', '=', - '[', ']', '{', '}', '\\', '|', ';', ':', '\'', '"', '<', ',', '>', '.', '?', '/', ' '} - var charsStr string - for _, char := range chars { - charsStr += string(char) - } - - if strings.ContainsAny(cloudDirName, charsStr) { - return false - } - return true -} - func getIgnoreLines() (ret []string) { ignore := filepath.Join(util.DataDir, ".siyuan", "syncignore") err := os.MkdirAll(filepath.Dir(ignore), 0755) From f3d7568b52c9de584d0b03e488de0554112c7f23 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Wed, 2 Nov 2022 20:15:46 +0800 Subject: [PATCH 3/3] =?UTF-8?q?:art:=20=E5=BC=80=E6=BA=90=E4=BA=91?= =?UTF-8?q?=E7=AB=AF=E5=90=8C=E6=AD=A5=E6=9C=8D=E5=8A=A1=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=20https://github.com/siyuan-note/siyuan/issues/6445?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/sync.go | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/kernel/model/sync.go b/kernel/model/sync.go index eb578ec88..b783a0904 100644 --- a/kernel/model/sync.go +++ b/kernel/model/sync.go @@ -30,6 +30,7 @@ import ( "github.com/dustin/go-humanize" "github.com/siyuan-note/dejavu/cloud" "github.com/siyuan-note/logging" + "github.com/siyuan-note/siyuan/kernel/conf" "github.com/siyuan-note/siyuan/kernel/sql" "github.com/siyuan-note/siyuan/kernel/treenode" "github.com/siyuan-note/siyuan/kernel/util" @@ -69,7 +70,11 @@ func BootSyncData() { util.IncBootProgress(3, "Syncing data from the cloud...") BootSyncSucc = 0 - if !IsSubscriber() || !Conf.Sync.Enabled || "" == Conf.Sync.CloudName || !cloud.IsValidCloudDirName(Conf.Sync.CloudName) { + if !Conf.Sync.Enabled || !cloud.IsValidCloudDirName(Conf.Sync.CloudName) { + return + } + + if !IsSubscriber() && conf.ProviderSiYuan == Conf.Sync.Provider { return } @@ -123,17 +128,25 @@ func SyncData(boot, exit, byHand bool) { if exit { ExitSyncSucc = 0 } - if !IsSubscriber() || !Conf.Sync.Enabled || "" == Conf.Sync.CloudName { + + if !Conf.Sync.Enabled { if byHand { - if "" == Conf.Sync.CloudName { - util.PushMsg(Conf.Language(123), 5000) - } else if !Conf.Sync.Enabled { - util.PushMsg(Conf.Language(124), 5000) - } + util.PushMsg(Conf.Language(124), 5000) } return } + if !cloud.IsValidCloudDirName(Conf.Sync.CloudName) { + if byHand { + util.PushMsg(Conf.Language(123), 5000) + } + return + } + + if !IsSubscriber() && conf.ProviderSiYuan == Conf.Sync.Provider { + return + } + if !cloud.IsValidCloudDirName(Conf.Sync.CloudName) { return }