-
Notifications
You must be signed in to change notification settings - Fork 15
Conversation
database/postgres/pgdatabase.go
Outdated
if len(resources) == 0 { | ||
return nil | ||
} | ||
|
||
if shouldCascade { | ||
if err := deleteResourceByCQId(ctx, p.pool, resources, cascadeDeleteFilters); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an alternative we could enable ON CONFLICT UPDATE
, but that checks PK collisions (which we want to keep/see/reported) and not necessarily a cq_id
collision.
Or running this + the insert below in a TX might be a (costly?) option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think one of the above needs to be the solution, due to the fact that when data is deleted during fetch, can cause bad user-experience, even if it is then re-inserted again anyway (@yevgenypats @roneli @bbernays).
Not sure which we should choose between TX and ON CONFLICT UPDATE
. One thing idea in favor of using deleteResourceByCQId
is just consistency with current behaviour in copyFrom
. i.e., if we delete by cq-id in copyFrom
, we should do the same kind of deletions in the fallback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point I don't think I have ever seen an issue that stems from DB performance on insert. The only incident that I am aware of is that someone had issues because they needed to vacuum their db. So overall, I am not very concerned about DB performance as our biggest bottleneck is by far and away the rate we can grab data from provider APIs...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That being said, I like the idea and consistency of doing the deletion + insertion in a TX for each of our 3 methods of insertion (copy, insert multiple and singular insert)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 0264392
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
#265 Continued
I think current code assumes
CopyFrom
trial will delete all dupe ids, but it’s in a TX so as soon as it fails everything is reverted back to cause us more problems