mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-14 01:17:52 +00:00
fix(sync): use nanosecond precision for bindings version to ensure uniqueness
Use UnixNano for version field while keeping Unix seconds for updated_at timestamp. This ensures version changes are detected even when multiple syncs occur within the same second.
This commit is contained in:
@@ -651,7 +651,9 @@ func (s *SyncService) writeBindingsSnapshot(ctx context.Context, pipe redis.Pipe
|
||||
snap routing.BindingSnapshot
|
||||
}
|
||||
snaps := make(map[string]*routing.BindingSnapshot)
|
||||
now := time.Now().Unix()
|
||||
now := time.Now()
|
||||
nowUnix := now.Unix()
|
||||
version := now.UnixNano()
|
||||
|
||||
for _, b := range bindings {
|
||||
if strings.TrimSpace(b.Status) != "" && strings.TrimSpace(b.Status) != "active" {
|
||||
@@ -677,7 +679,7 @@ func (s *SyncService) writeBindingsSnapshot(ctx context.Context, pipe redis.Pipe
|
||||
Namespace: ns,
|
||||
PublicModel: pm,
|
||||
Status: "active",
|
||||
UpdatedAt: now,
|
||||
UpdatedAt: nowUnix,
|
||||
}
|
||||
snaps[key] = snap
|
||||
}
|
||||
@@ -699,7 +701,6 @@ func (s *SyncService) writeBindingsSnapshot(ctx context.Context, pipe redis.Pipe
|
||||
candidate.Error = "no_provider"
|
||||
}
|
||||
|
||||
nowUnix := time.Now().Unix()
|
||||
for _, k := range keys {
|
||||
if k.status != "" && k.status != "active" {
|
||||
continue
|
||||
@@ -729,8 +730,8 @@ func (s *SyncService) writeBindingsSnapshot(ctx context.Context, pipe redis.Pipe
|
||||
}
|
||||
|
||||
meta := map[string]string{
|
||||
"version": fmt.Sprintf("%d", now),
|
||||
"updated_at": fmt.Sprintf("%d", now),
|
||||
"version": fmt.Sprintf("%d", version),
|
||||
"updated_at": fmt.Sprintf("%d", nowUnix),
|
||||
"source": "cp_builtin",
|
||||
}
|
||||
if err := pipe.HSet(ctx, "meta:bindings_meta", meta).Err(); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user