Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

fix: Delete by cq_id before insertion #266

Merged
merged 3 commits into from
May 23, 2022
Merged

fix: Delete by cq_id before insertion #266

merged 3 commits into from
May 23, 2022

Conversation

disq
Copy link
Member

@disq disq commented May 20, 2022

#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

@disq disq requested a review from a team as a code owner May 20, 2022 13:06
@disq disq requested review from irmatov, shimonp21 and bbernays and removed request for a team May 20, 2022 13:06
@github-actions github-actions bot added the fix label May 20, 2022
@disq disq mentioned this pull request May 20, 2022
@disq disq requested a review from roneli May 20, 2022 13:09
if len(resources) == 0 {
return nil
}

if shouldCascade {
if err := deleteResourceByCQId(ctx, p.pool, resources, cascadeDeleteFilters); err != nil {
Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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...

Copy link
Contributor

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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 0264392

@github-actions github-actions bot added fix and removed fix labels May 20, 2022
@disq disq requested a review from shimonp21 May 23, 2022 07:37
Copy link
Contributor

@roneli roneli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@disq disq merged commit 1f74be7 into main May 23, 2022
@disq disq deleted the fix/insert-fix branch May 23, 2022 07:54
disq added a commit that referenced this pull request May 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants