Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure transitive deletion triggers are run for CASCADE_DELETE_INVALIDATE_CACHE #66

Merged
merged 1 commit into from
Jul 23, 2020

Conversation

wschurman
Copy link
Member

Why

Before this PR, if a field was CASCADE_DELETE_INVALIDATE_CACHE deletion behavior it wouldn't run transitive triggers even though the underlying reference would be deleted by the database foreign key.

This fixes that by doing all recursing through the delete method and just not deleting from the database if a boolean flag is specified. While I'm normally against boolean flags, because this is a private internal method I'm more okay with it.

Concretely the case this fixes is:
Entity A has field b_id with behavior CASCADE_DELETE_INVALIDATE_CACHE referencing an Entity B.
Entity B has a trigger that runs during or after deletion (including afterCommit).

Previously B's triggers wouldn't be run. Now they are run.

Test Plan

Run tests. This is very extensively tested so the fact that no test changes were needed is reassuring.

@wschurman wschurman requested review from ide and quinlanj July 23, 2020 00:20
@codecov
Copy link

codecov bot commented Jul 23, 2020

Codecov Report

Merging #66 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #66   +/-   ##
=======================================
  Coverage   94.55%   94.55%           
=======================================
  Files          59       59           
  Lines        1488     1488           
  Branches      165      167    +2     
=======================================
  Hits         1407     1407           
  Misses         79       79           
  Partials        2        2           
Flag Coverage Δ
#integration 94.55% <100.00%> (ø)
#unittest 94.55% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/entity/src/EntityMutator.ts 97.98% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fd6060c...2ad9de9. Read the comment docs.

private async deleteInTransactionAsync(): Promise<Result<void>> {
private async deleteInTransactionAsync(
processedEntityIdentifiersFromTransitiveDeletions: Set<string> = new Set(),
skipDatabaseDeletion: boolean = false
Copy link
Member

Choose a reason for hiding this comment

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

Could also write:

Suggested change
skipDatabaseDeletion: boolean = false
{ skipDatabaseDeletion = false }: { skipDatabaseDeletion: boolean} = {}

(yeah it's verbose but it's what we've got) This said I think the existing code is reasonable to read as-is.

Copy link
Member Author

@wschurman wschurman Jul 23, 2020

Choose a reason for hiding this comment

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

I'll probably leave it as-is. This makes me wonder how much effort goes into optimizing these one-off named param objects like this in v8.

@wschurman wschurman merged commit 5744c51 into master Jul 23, 2020
@wschurman wschurman deleted the @wschurman/transitive-trigger-deletion branch July 23, 2020 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants