From 04587ca695ebc36bee2a0f5af406c0c3a08ac948 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 26 Jul 2025 09:40:39 +0800 Subject: [PATCH 1/3] :art: Database grouping by field https://github.com/siyuan-note/siyuan/issues/10964 --- kernel/model/attribute_view.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index cd215741d..2c3cf2188 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -77,7 +77,7 @@ func sortAttributeViewGroup(avID, blockID, previousGroupID, groupID string) (err } view.Groups = append(view.Groups[:index], view.Groups[index+1:]...) - for i, g := range group.Groups { + for i, g := range view.Groups { if g.ID == previousGroupID { previousIndex = i + 1 break From a76a5209967200aa5f46498ccce9c951c23fc4e0 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 26 Jul 2025 10:11:15 +0800 Subject: [PATCH 2/3] :art: Database grouping by field https://github.com/siyuan-note/siyuan/issues/10964 --- kernel/model/attribute_view.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index 2c3cf2188..df7d09b0e 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -1674,25 +1674,25 @@ func genAttrViewViewGroups(view *av.View, attrView *av.AttributeView) { // 过去 30 天之前的按月分组 // 过去 30 天、过去 7 天、昨天、今天、明天、未来 7 天、未来 30 天 // 未来 30 天之后的按月分组 - now := time.Now() - now = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local) - if contentTime.Before(now.AddDate(0, 0, -30)) { + todayStart := time.Now() + todayStart = time.Date(todayStart.Year(), todayStart.Month(), todayStart.Day(), 0, 0, 0, 0, time.Local) + if contentTime.Before(todayStart.AddDate(0, 0, -30)) { groupName = contentTime.Format("2006-01") - } else if contentTime.Before(now.AddDate(0, 0, -7)) { + } else if contentTime.Before(todayStart.AddDate(0, 0, -7)) { groupName = groupNameLast30Days - } else if contentTime.Before(now.AddDate(0, 0, -1)) { + } else if contentTime.Before(todayStart.AddDate(0, 0, -1)) { groupName = groupNameLast7Days - } else if contentTime.Before(now) { + } else if contentTime.Before(todayStart) { groupName = groupNameYesterday - } else if contentTime.After(now) && contentTime.Before(now.AddDate(0, 0, 1)) { + } else if contentTime.After(todayStart) && contentTime.Before(todayStart.AddDate(0, 0, 1)) { groupName = groupNameToday - } else if contentTime.After(now.AddDate(0, 0, 1)) || contentTime.Equal(now.AddDate(0, 0, 1)) { + } else if (contentTime.After(todayStart.AddDate(0, 0, 1)) && contentTime.Before(todayStart.AddDate(0, 0, 2))) || contentTime.Equal(todayStart.AddDate(0, 0, 1)) { groupName = groupNameTomorrow - } else if contentTime.After(now.AddDate(0, 0, 30)) { + } else if contentTime.After(todayStart.AddDate(0, 0, 30)) { groupName = contentTime.Format("2006-01") - } else if contentTime.After(now.AddDate(0, 0, 7)) { + } else if contentTime.After(todayStart.AddDate(0, 0, 7)) { groupName = groupNameNext30Days - } else if contentTime.After(now.AddDate(0, 0, 1)) { + } else if contentTime.After(todayStart.AddDate(0, 0, 1)) { groupName = groupNameNext7Days } } From e1471ff5850c64759d68d108268e1176313e90d8 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 26 Jul 2025 10:45:40 +0800 Subject: [PATCH 3/3] :art: Database grouping by field https://github.com/siyuan-note/siyuan/issues/10964 --- kernel/model/attribute_view.go | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index df7d09b0e..9f2973872 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -1677,23 +1677,23 @@ func genAttrViewViewGroups(view *av.View, attrView *av.AttributeView) { todayStart := time.Now() todayStart = time.Date(todayStart.Year(), todayStart.Month(), todayStart.Day(), 0, 0, 0, 0, time.Local) if contentTime.Before(todayStart.AddDate(0, 0, -30)) { - groupName = contentTime.Format("2006-01") + groupName = "0" + contentTime.Format("2006-01") // 开头的数字用于排序,下同 } else if contentTime.Before(todayStart.AddDate(0, 0, -7)) { - groupName = groupNameLast30Days + groupName = "1" + groupNameLast30Days } else if contentTime.Before(todayStart.AddDate(0, 0, -1)) { - groupName = groupNameLast7Days + groupName = "2" + groupNameLast7Days } else if contentTime.Before(todayStart) { - groupName = groupNameYesterday - } else if contentTime.After(todayStart) && contentTime.Before(todayStart.AddDate(0, 0, 1)) { - groupName = groupNameToday - } else if (contentTime.After(todayStart.AddDate(0, 0, 1)) && contentTime.Before(todayStart.AddDate(0, 0, 2))) || contentTime.Equal(todayStart.AddDate(0, 0, 1)) { - groupName = groupNameTomorrow + groupName = "3" + groupNameYesterday + } else if (contentTime.After(todayStart) || contentTime.Equal(todayStart)) && contentTime.Before(todayStart.AddDate(0, 0, 1)) { + groupName = "4" + groupNameToday } else if contentTime.After(todayStart.AddDate(0, 0, 30)) { - groupName = contentTime.Format("2006-01") + groupName = "8" + contentTime.Format("2006-01") } else if contentTime.After(todayStart.AddDate(0, 0, 7)) { - groupName = groupNameNext30Days + groupName = "7" + groupNameNext30Days } else if contentTime.After(todayStart.AddDate(0, 0, 1)) { - groupName = groupNameNext7Days + groupName = "6" + groupNameNext7Days + } else { + groupName = "5" + groupNameTomorrow } } } @@ -1756,6 +1756,12 @@ func genAttrViewViewGroups(view *av.View, attrView *av.AttributeView) { return view.Groups[i].Name > view.Groups[j].Name }) } + + if group.Method == av.GroupMethodDateRelative { + for _, v := range view.Groups { + v.Name = v.Name[1:] // 去掉前缀排序数字 + } + } } func isGroupByDate(view *av.View) bool {