yumi-golang/internal/service/taskcenter/archive_manifest.go
2026-07-18 18:56:15 +08:00

75 lines
2.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package taskcenter
import (
"context"
"time"
"chatapp3-golang/internal/model"
"gorm.io/gorm/clause"
)
const (
archiveManifestObjectArchive = "ARCHIVE"
archiveManifestObjectRecovery = "GC_RECOVERY"
archiveManifestVerified = "VERIFIED"
)
// upsertArchiveManifest 以 COS key 为不可变对象身份。重验历史对象时只刷新校验结果,
// 不创建重复清单GC 删除前可据此确认看到的是同一个对象版本和摘要。
func (s *Service) upsertArchiveManifest(ctx context.Context, row model.TaskCenterArchiveManifest) error {
now := time.Now()
if row.CreateTime.IsZero() {
row.CreateTime = now
}
row.UpdateTime = now
return s.db.WithContext(ctx).Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "cos_key"}},
DoUpdates: clause.Assignments(map[string]any{
"object_type": row.ObjectType,
"run_id": row.RunID,
"parent_cos_key": row.ParentCOSKey,
"sha256": row.SHA256,
"etag": row.ETag,
"compressed_size": row.CompressedSize,
"row_count": row.RowCount,
"min_outbox_id": row.MinOutboxID,
"max_outbox_id": row.MaxOutboxID,
"min_occurred_at": row.MinOccurredAt,
"max_occurred_at": row.MaxOccurredAt,
"verification_status": row.VerificationStatus,
"verified_at": row.VerifiedAt,
"update_time": row.UpdateTime,
}),
}).Create(&row).Error
}
func archiveGroupBounds(rows []model.TaskCenterEventArchiveOutbox) (*int64, *int64, *time.Time, *time.Time) {
if len(rows) == 0 {
return nil, nil, nil, nil
}
minID, maxID := rows[0].ID, rows[0].ID
var minOccurredAt, maxOccurredAt *time.Time
for _, row := range rows {
if row.ID < minID {
minID = row.ID
}
if row.ID > maxID {
maxID = row.ID
}
if row.OccurredAt.IsZero() {
continue
}
value := row.OccurredAt
if minOccurredAt == nil || value.Before(*minOccurredAt) {
copyValue := value
minOccurredAt = &copyValue
}
if maxOccurredAt == nil || value.After(*maxOccurredAt) {
copyValue := value
maxOccurredAt = &copyValue
}
}
return &minID, &maxID, minOccurredAt, maxOccurredAt
}