Browse Source

Merge remote-tracking branch 'origin/dev' into dev

Vanessa 1 năm trước cách đây
mục cha
commit
9f237766f8
3 tập tin đã thay đổi với 39 bổ sung40 xóa
  1. 6 0
      kernel/av/av.go
  2. 32 32
      kernel/av/filter.go
  3. 1 8
      kernel/model/attribute_view.go

+ 6 - 0
kernel/av/av.go

@@ -340,6 +340,7 @@ func SaveAttributeView(av *AttributeView) (err error) {
 			// 补全 block 的创建时间和更新时间
 			for _, v := range kv.Values {
 				if 0 == v.Block.Created {
+					logging.LogWarnf("block [%s] created time is empty", v.BlockID)
 					if "" == v.Block.ID {
 						v.Block.ID = v.BlockID
 						if "" == v.Block.ID {
@@ -357,6 +358,7 @@ func SaveAttributeView(av *AttributeView) (err error) {
 					}
 				}
 				if 0 == v.Block.Updated {
+					logging.LogWarnf("block [%s] updated time is empty", v.BlockID)
 					v.Block.Updated = v.Block.Created
 				}
 			}
@@ -375,6 +377,7 @@ func SaveAttributeView(av *AttributeView) (err error) {
 					val.KeyID = kv.Key.ID
 				}
 				if "" == v.KeyID {
+					logging.LogWarnf("value [%s] key id is empty", v.ID)
 					v.KeyID = kv.Key.ID
 				}
 
@@ -417,10 +420,12 @@ func SaveAttributeView(av *AttributeView) (err error) {
 
 			// 补全值的创建时间和更新时间
 			if "" == v.ID {
+				logging.LogWarnf("value id is empty")
 				v.ID = ast.NewNodeID()
 			}
 
 			if 0 == v.CreatedAt {
+				logging.LogWarnf("value [%s] created time is empty", v.ID)
 				createdStr := v.ID[:len("20060102150405")]
 				created, parseErr := time.ParseInLocation("20060102150405", createdStr, time.Local)
 				if nil == parseErr {
@@ -431,6 +436,7 @@ func SaveAttributeView(av *AttributeView) (err error) {
 			}
 
 			if 0 == v.UpdatedAt {
+				logging.LogWarnf("value [%s] updated time is empty", v.ID)
 				v.UpdatedAt = v.CreatedAt
 			}
 		}

+ 32 - 32
kernel/av/filter.go

@@ -55,7 +55,7 @@ const (
 type RelativeDate struct {
 	Count     int                   `json:"count"`     // 数量
 	Unit      RelativeDateUnit      `json:"unit"`      // 单位:0 天、1 周、2 月、3 年
-	Direction RelativeDateDirection `json:"direction"` // 方向:-1 前、0 、1 后
+	Direction RelativeDateDirection `json:"direction"` // 方向:-1 前、0 当前、1 后
 }
 
 type FilterOperator string
@@ -571,19 +571,19 @@ func calcRelativeTimeRegion(count int, unit RelativeDateUnit, direction Relative
 	case RelativeDateUnitDay:
 		switch direction {
 		case RelativeDateDirectionBefore:
-			// 结束时间使用今天的开始时间
+			// 结束时间:今天的 0 点
 			end = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
-			// 开始时间使用结束时间减去 count 天
+			// 开始时间结束时间减去 count 天
 			start = end.AddDate(0, 0, -count)
 		case RelativeDateDirectionThis:
-			// 开始时间使用今天的开始时间
+			// 开始时间:今天的 0 点
 			start = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
-			// 结束时间使用开始时间加上 count 天
-			end = start.AddDate(0, 0, count)
+			// 结束时间:今天的 23:59:59.999999999
+			end = time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 999999999, now.Location())
 		case RelativeDateDirectionAfter:
-			// 开始时间使用今天的结束时间
+			// 开始时间:今天的 23:59:59.999999999
 			start = time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 999999999, now.Location())
-			// 结束时间使用开始时间加上 count 天
+			// 结束时间开始时间加上 count 天
 			end = start.AddDate(0, 0, count)
 		}
 	case RelativeDateUnitWeek:
@@ -593,55 +593,55 @@ func calcRelativeTimeRegion(count int, unit RelativeDateUnit, direction Relative
 		}
 		switch direction {
 		case RelativeDateDirectionBefore:
-			// 结束时间使用本周的开始时间
-			end = time.Date(now.Year(), now.Month(), now.Day()-weekday, 0, 0, 0, 0, now.Location())
-			// 开始时间使用结束时间减去 count*7 天
+			// 结束时间:本周的周一
+			end = time.Date(now.Year(), now.Month(), now.Day()-weekday+1, 0, 0, 0, 0, now.Location())
+			// 开始时间结束时间减去 count*7 天
 			start = end.AddDate(0, 0, -count*7)
 		case RelativeDateDirectionThis:
-			// 开始时间使用本周的开始时间
-			start = time.Date(now.Year(), now.Month(), now.Day()-weekday, 0, 0, 0, 0, now.Location())
-			// 结束时间使用开始时间加上 count*7 天
-			end = start.AddDate(0, 0, count*7)
+			// 开始时间:本周的周一
+			start = time.Date(now.Year(), now.Month(), now.Day()-weekday+1, 0, 0, 0, 0, now.Location())
+			// 结束时间:本周的周日
+			end = time.Date(now.Year(), now.Month(), now.Day()-weekday+7, 23, 59, 59, 999999999, now.Location())
 		case RelativeDateDirectionAfter:
-			//  开始时间使用本周的结束时间
+			//  开始时间:本周的周日
 			start = time.Date(now.Year(), now.Month(), now.Day()-weekday+7, 23, 59, 59, 999999999, now.Location())
-			// 结束时间使用开始时间加上 count*7 天
+			// 结束时间开始时间加上 count*7 天
 			end = start.AddDate(0, 0, count*7)
 		}
 	case RelativeDateUnitMonth:
 		switch direction {
 		case RelativeDateDirectionBefore:
-			// 结束时间使用本月的开始时间
+			// 结束时间:本月的 1 号
 			end = time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
-			// 开始时间使用结束时间减去 count 个月
+			// 开始时间结束时间减去 count 个月
 			start = end.AddDate(0, -count, 0)
 		case RelativeDateDirectionThis:
-			// 开始时间使用本月的开始时间
+			// 开始时间:本月的 1 号
 			start = time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
-			// 结束时间使用开始时间加上 count 个月
-			end = start.AddDate(0, count, 0)
+			// 结束时间:下个月的 1 号减去 1 纳秒
+			end = time.Date(now.Year(), now.Month()+1, 1, 0, 0, 0, 0, now.Location()).Add(-time.Nanosecond)
 		case RelativeDateDirectionAfter:
-			// 开始时间使用本月的结束时间
+			// 开始时间:下个月的 1 号减去 1 纳秒
 			start = time.Date(now.Year(), now.Month()+1, 1, 0, 0, 0, 0, now.Location()).Add(-time.Nanosecond)
-			// 结束时间使用开始时间加上 count 个月
+			// 结束时间开始时间加上 count 个月
 			end = start.AddDate(0, count, 0)
 		}
 	case RelativeDateUnitYear:
 		switch direction {
 		case RelativeDateDirectionBefore:
-			// 结束时间使用今年的开始时间
+			// 结束时间:今年的 1 月 1 号
 			end = time.Date(now.Year(), 1, 1, 0, 0, 0, 0, now.Location())
-			// 开始时间使用结束时间减去 count 年
+			// 开始时间结束时间减去 count 年
 			start = end.AddDate(-count, 0, 0)
 		case RelativeDateDirectionThis:
-			// 开始时间使用今年的开始时间
+			// 开始时间:今年的 1 月 1 号
 			start = time.Date(now.Year(), 1, 1, 0, 0, 0, 0, now.Location())
-			// 结束时间使用开始时间加上 count 年
-			end = start.AddDate(count, 0, 0)
+			// 结束时间:明年的 1 月 1 号减去 1 纳秒
+			end = time.Date(now.Year()+1, 1, 1, 0, 0, 0, 0, now.Location()).Add(-time.Nanosecond)
 		case RelativeDateDirectionAfter:
-			// 开始时间使用今年的结束时间
-			start = time.Date(now.Year()+1, 1, 1, 0, 0, 0, 0, now.Location()).Add(-time.Nanosecond)
-			// 结束时间使用开始时间加上 count 年
+			// 开始时间:今年的 12 月 31 号
+			start = time.Date(now.Year(), 12, 31, 23, 59, 59, 999999999, now.Location())
+			// 结束时间开始时间加上 count 年
 			end = start.AddDate(count, 0, 0)
 		}
 	}

+ 1 - 8
kernel/model/attribute_view.go

@@ -2129,7 +2129,6 @@ func addAttributeViewBlock(avID, blockID, previousBlockID, addingBlockID string,
 				blockValue.IsDetached = isDetached
 				blockValue.Block.Content = content
 				blockValue.UpdatedAt = now
-				util.PushMsg(Conf.language(242), 3000)
 				err = av.SaveAttributeView(attrView)
 			}
 			return
@@ -2971,7 +2970,7 @@ func UpdateAttributeViewCell(tx *Transaction, avID, keyID, rowID, cellID string,
 		}
 
 		for _, value := range keyValues.Values {
-			if cellID == value.ID {
+			if cellID == value.ID || rowID == value.BlockID {
 				val = value
 				val.Type = keyValues.Key.Type
 				break
@@ -3003,12 +3002,6 @@ func UpdateAttributeViewCell(tx *Transaction, avID, keyID, rowID, cellID string,
 		return
 	}
 
-	if "" == val.ID {
-		// 有时前端会误调用该接口(比如创建完快速切换),这里判断一下,避免误更新刚刚创建的值
-		// Primary key value unexpectedly updated when database adds row https://github.com/siyuan-note/siyuan/issues/11018
-		return
-	}
-
 	if av.KeyTypeNumber == val.Type {
 		if nil != val.Number && !val.Number.IsNotEmpty {
 			val.Number.Content = 0