diff --git a/pkg/services/annotations/annotationsimpl/xorm_store.go b/pkg/services/annotations/annotationsimpl/xorm_store.go index 16983586753..21f1aeec6cd 100644 --- a/pkg/services/annotations/annotationsimpl/xorm_store.go +++ b/pkg/services/annotations/annotationsimpl/xorm_store.go @@ -78,7 +78,10 @@ func (r *xormRepositoryImpl) AddMany(ctx context.Context, items []annotations.It hasTags := make([]annotations.Item, 0) hasNoTags := make([]annotations.Item, 0) - for i, item := range items { + for i := range items { + // The validation logic needs to work in terms of pointers. + // So, force everything else to work in terms of pointers too, to avoid any implicit extra copying. + item := &items[i] tags := tag.ParseTagPairs(item.Tags) item.Tags = tag.JoinTagPairs(tags) item.Created = timeNow().UnixNano() / int64(time.Millisecond) @@ -86,14 +89,14 @@ func (r *xormRepositoryImpl) AddMany(ctx context.Context, items []annotations.It if item.Epoch == 0 { item.Epoch = item.Created } - if err := r.validateItem(&items[i]); err != nil { + if err := r.validateItem(item); err != nil { return err } if len(item.Tags) > 0 { - hasTags = append(hasTags, item) + hasTags = append(hasTags, *item) } else { - hasNoTags = append(hasNoTags, item) + hasNoTags = append(hasNoTags, *item) } } diff --git a/pkg/services/annotations/annotationsimpl/xorm_store_test.go b/pkg/services/annotations/annotationsimpl/xorm_store_test.go index 907f1e94839..fbe44f9c680 100644 --- a/pkg/services/annotations/annotationsimpl/xorm_store_test.go +++ b/pkg/services/annotations/annotationsimpl/xorm_store_test.go @@ -185,6 +185,11 @@ func TestIntegrationAnnotations(t *testing.T) { inserted, err := repo.Get(context.Background(), query) require.NoError(t, err) assert.Len(t, inserted, count) + for _, ins := range inserted { + require.Equal(t, int64(12), ins.Time) + require.Equal(t, int64(12), ins.TimeEnd) + require.Equal(t, ins.Created, ins.Updated) + } }) t.Run("Can batch-insert annotations with tags", func(t *testing.T) {