fix: upsertSource function

now returning the correct source after finding it or creating it
This commit is contained in:
SoXX 2024-08-27 09:35:25 +02:00
parent f708706d50
commit 0070352623

View File

@ -14,7 +14,7 @@ func upsertSource(ctx context.Context, source models.Source) (models.Source, err
var err error
source, err = database.GetSourceByDomain(ctx, source.Domain)
localSource, err := database.GetSourceByDomain(ctx, source.Domain)
if err != nil {
if err.Error() == "Database error: NoDataFound" {
span.AddEvent("No Source found, initializing source")
@ -32,6 +32,8 @@ func upsertSource(ctx context.Context, source models.Source) (models.Source, err
span.AddEvent("Source created")
log.WithContext(ctx).WithError(err).WithField("source_domain", source.Domain).WithField("source_id", source.ID).Info("Source created!")
return source, nil
} else {
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
@ -40,5 +42,5 @@ func upsertSource(ctx context.Context, source models.Source) (models.Source, err
}
}
return source, nil
return localSource, nil
}