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

feat: handleOutdatedSuggestions gracefully #671

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Conversation

sandsinh
Copy link

@sandsinh sandsinh commented Feb 18, 2025

Problem:
sync suggestions deletes outdated suggestions from the db.

Proposed solution:
For fix history phase 1, we are proposing to retain the suggestions and mark them 'OUTDATED' if they are not found in the latest audit run.

Changes:

  1. After this change, any existing suggestion not found in the audit result will be marked as 'OUTDATED' if their current status is not 'FIXED', 'OUTDATED', 'ERROR', 'SKIPPED'.
  2. Any 'FIXED' or 'OUTDATED' suggestion found in the audit result will be marked as 'NEW'. (Covers cases for possible regression)

Please ensure your pull request adheres to the following guidelines:

  • make sure to link the related issues in this description
  • when merging / squashing, make sure the fixed issue references are visible in the commits, for easy compilation of release notes

Related Issues

Thanks for contributing!

@sandsinh sandsinh marked this pull request as draft February 18, 2025 20:13
Copy link

This PR will trigger a minor release when merged.

@sandsinh sandsinh marked this pull request as ready for review February 19, 2025 15:18
@sandsinh sandsinh marked this pull request as draft February 20, 2025 18:43
@sandsinh sandsinh marked this pull request as ready for review February 21, 2025 11:05
@@ -74,18 +108,20 @@ export async function retrieveAuditById(dataAccess, auditId, log) {
export async function syncSuggestions({
opportunity,
newData,
context,
buildKey,
mapNewSuggestion,
log,
}) {
const newDataKeys = new Set(newData.map(buildKey));
const existingSuggestions = await opportunity.getSuggestions();
Copy link
Member

Choose a reason for hiding this comment

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

while already there, with this change, this will possibly cause performance issues as the list of suggestions grows forevermore. at the very least a status filter should be employed. in fact the handling of outdated suggestions could be implemented as a bulk-operation as part of the SuggestionCollection in data access. We should not have use of data access queries in an unbounded fashion.

Copy link
Author

Choose a reason for hiding this comment

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

We have three operations here:

  1. handleOutdatedSuggestion
    This method targets only 'NEW' and 'IN_PROGRESS' suggestions, having bounded query with status filter makes sense here.

  2. updateExistingSuggestion :
    This method targets suggestions of all statuses. No bounded query can be written for status filter. [Based on our assumption that even FIXED or OUTDATED suggestion can be reopened in future]

  3. createNewSuggestion :
    This method also requires information for all the suggestions irrespective of the statuses. No bounded query here as well. [Based on our assumption that even FIXED or OUTDATED suggestion can be reopened in future]

Bounding the operations 2 & 3 to 'NEW' and 'IN_PROGRESS' suggestions could work but as a consequence we would have to allow multiple suggestions with the same dataKeys in the db. This means that instead of reopening an existing FIXED or OUTDATED suggestion, we will create 'NEW' suggestions if the audit find the same issue again.

Note: Having the ability to query using the dataKeys would help us write bounded queries very efficiently for all the operations. But i think it is not possible yet.

@solaris007 Let me know what are you thoughts on this.

SuggestionDataAccess.STATUSES.OUTDATED,
].includes(existing.getStatus())) {
log.warn('Resolved suggestion found in audit. Possible regression.');
existing.setStatus(SuggestionDataAccess.STATUSES.NEW);
Copy link
Member

Choose a reason for hiding this comment

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

there's already a Suggestion.bulkUpdateStatus method...

Copy link
Author

Choose a reason for hiding this comment

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

I believe setStatus does not save the suggestion but only updates the entity locally. Save operation is performed later at L146.

@sandsinh sandsinh requested a review from solaris007 February 24, 2025 10:11
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