From 4d209f2a903bcfbddf6d2fc6c8df8f86334b6210 Mon Sep 17 00:00:00 2001 From: SoXX Date: Fri, 1 Nov 2024 22:14:29 +0100 Subject: [PATCH] fix: favorites creation timestamps and remove duplicate imports --- pkg/plug/algorithm.go | 6 ++++++ pkg/plug/scrape.go | 7 +------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/plug/algorithm.go b/pkg/plug/algorithm.go index 3ea9fe5..c080abf 100644 --- a/pkg/plug/algorithm.go +++ b/pkg/plug/algorithm.go @@ -9,6 +9,7 @@ import ( "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" "slices" + "time" ) type User struct { @@ -132,7 +133,12 @@ outer: if len(anthroveFaves) > 0 { span.AddEvent("Executing CreateUserFavoriteInBatch") + for i, fav := range anthroveFaves { + fav.CreatedAt = time.Now().Add(time.Millisecond * time.Duration(i) * -1) + } + slices.Reverse(anthroveFaves) + err = database.CreateUserFavoriteInBatch(ctx, anthroveFaves, BatchSize) if err != nil { span.RecordError(err) diff --git a/pkg/plug/scrape.go b/pkg/plug/scrape.go index f02e13f..5f1262d 100644 --- a/pkg/plug/scrape.go +++ b/pkg/plug/scrape.go @@ -2,9 +2,6 @@ package plug import ( "context" - "slices" - "time" - "git.anthrove.art/Anthrove/otter-space-sdk/v4/pkg/database" "git.anthrove.art/Anthrove/otter-space-sdk/v4/pkg/models" log "github.com/sirupsen/logrus" @@ -12,6 +9,7 @@ import ( "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" "gorm.io/gorm" + "slices" ) var BatchSize = 50 @@ -98,9 +96,6 @@ func BatchPostProcessingWithSummery(ctx context.Context, userSource models.UserS return found }) { anthroveFaves = append(anthroveFaves, models.UserFavorite{ - BaseModel: models.BaseModel[models.UserFavoriteID]{ - CreatedAt: time.Now().Add(time.Millisecond * time.Duration(i) * -1), - }, UserID: userSource.UserID, PostID: post.ID, UserSourceID: userSource.ID,