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 repeat deletion Issue by implementing Clear volatiles for tree element #1417

Merged
merged 5 commits into from
Jul 4, 2024

Conversation

shubham1g5
Copy link
Contributor

@shubham1g5 shubham1g5 commented Jul 3, 2024

Technical Summary

https://dimagi.atlassian.net/browse/USH-4708 (Deleting a repeat was causing errors in resolving references for remaining repeat nodes)

After deleting a repeat, a node's reference can change due to change in repeat index of the node. Therefore we need to expire the existing cached references for TreeElements.

Safety Assurance

Safety story

  • Should only affect repeat deletion which is covered by test

Automated test coverage

Added in the PR plus in dimagi/formplayer#1597

QA Plan

None

Special deploy instructions

  • This PR can be deployed after merge with no further considerations.

Rollback instructions

  • This PR can be reverted after deploy with no further considerations.

Review

  • The set of people pinged as reviewers is appropriate for the level of risk of the change.

Duplicate PR

Automatically duplicate this PR as defined in contributing.md.

@shubham1g5 shubham1g5 mentioned this pull request Jul 3, 2024
3 tasks
@ctsims
Copy link
Member

ctsims commented Jul 3, 2024

I think we should be moving the logic for dispatching the volatile clearing from the DataInstance into each implementation of the method, where each implementation is required to both clear its own volatile state and dispatch the clear call to its children and other methods.

There are two big reasons why.
The biggest reason is that not all implementations of AbstractTreeElement actually have real child nodes. getChild() sometimes returns real elements, but also sometimes returns templates or virtual elements (say, for Repeat Indexing), so the "Get child count" and "dispatch to each child by multiplicity" approach could either end up triggering unintended consequences (walking the repeat tree and creating repeats, for instance), could return confusing elements, could miss data (say, nodes with a multiplicity of -2), or could just end up being slower than necessary
Additionally, right now there's just something a little awkward about requiring a DataInstance root for dispatching the tree walk in the first place.

I checked, and I don't think this will actually create meaningfully more repetitive implementations. The only thing this change makes a little confusing is that I think the default implementation of clearCache should definitely call getBase().clearVolatiles(), so we either need a second implementation of cleanCache that gives it a different target, or we should just take the hit and clear all of the caches

@shubham1g5 shubham1g5 force-pushed the clearVolatilesForTreeElement branch from aba181b to 6173371 Compare July 4, 2024 04:52
Copy link
Member

@ctsims ctsims left a comment

Choose a reason for hiding this comment

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

Looks good to me after the revisions! Thanks for getting this implemented across the models.

@shubham1g5 shubham1g5 merged commit 126ec06 into formplayer Jul 4, 2024
2 checks passed
@shubham1g5 shubham1g5 deleted the clearVolatilesForTreeElement branch July 4, 2024 05:18
@shubham1g5 shubham1g5 restored the clearVolatilesForTreeElement branch July 4, 2024 05:18
@shubham1g5
Copy link
Contributor Author

duplicate this branch 00c3d8a 9302ea1

public void cleanCache() {
referenceCache.clear();
getBase().clearVolatiles();
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to clarify, this cleanCache function is already being called in the correct way and we're just adding more cleanup code. Is that correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, for this particular use case of deleting repeat it gets called here

@snopoke snopoke deleted the clearVolatilesForTreeElement branch July 4, 2024 08:16
@shubham1g5 shubham1g5 restored the clearVolatilesForTreeElement branch July 4, 2024 10:17
@shubham1g5
Copy link
Contributor Author

duplicate this PR 00c3d8a 9302ea1

@shubham1g5 shubham1g5 deleted the clearVolatilesForTreeElement branch July 4, 2024 10:39
@shubham1g5 shubham1g5 restored the clearVolatilesForTreeElement branch July 5, 2024 06:21
@shubham1g5
Copy link
Contributor Author

duplicate this PR 00c3d8a 9302ea1

@shubham1g5 shubham1g5 deleted the clearVolatilesForTreeElement branch July 5, 2024 07:14
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.

3 participants