cookiebanner: rename DetectedTracker.InsertIfNotExists to Upsert
The method uses ON CONFLICT ... DO UPDATE, so the name now matches the actual behaviour. TrackerPattern.InsertIfNotExists keeps its name because it uses ON CONFLICT ... DO NOTHING. Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -2179,8 +2179,8 @@ func (s *Service) reportDetectedTracker(
|
|||||||
UpdatedAt: now,
|
UpdatedAt: now,
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := tracker.InsertIfNotExists(ctx, tx, scope); err != nil {
|
if _, err := tracker.Upsert(ctx, tx, scope); err != nil {
|
||||||
return fmt.Errorf("cannot insert detected tracker: %w", err)
|
return fmt.Errorf("cannot upsert detected tracker: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ type (
|
|||||||
DetectedTrackers []*DetectedTracker
|
DetectedTrackers []*DetectedTracker
|
||||||
)
|
)
|
||||||
|
|
||||||
func (dt *DetectedTracker) InsertIfNotExists(
|
func (dt *DetectedTracker) Upsert(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
tx pg.Tx,
|
tx pg.Tx,
|
||||||
scope Scoper,
|
scope Scoper,
|
||||||
@@ -109,7 +109,7 @@ ON CONFLICT (cookie_banner_id, tracker_type, identifier) DO UPDATE
|
|||||||
|
|
||||||
result, err := tx.Exec(ctx, q, args)
|
result, err := tx.Exec(ctx, q, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf("cannot insert detected tracker: %w", err)
|
return false, fmt.Errorf("cannot upsert detected tracker: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.RowsAffected() > 0, nil
|
return result.RowsAffected() > 0, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user