Skip to content

Fix loading results in second opened view#1806

Merged
koesie10 merged 1 commit intomainfrom
koesie10/fix-loading-results
Nov 29, 2022
Merged

Fix loading results in second opened view#1806
koesie10 merged 1 commit intomainfrom
koesie10/fix-loading-results

Conversation

@koesie10
Copy link
Copy Markdown
Member

When results were already cached in memory and the view requested the result, it would not be loaded because the event would not be fired. This fires the event when the result is loaded from cache as well, to ensure that the view always receives the result.

Checklist

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • [Maintainers only] If this pull request makes user-facing changes that require documentation changes, open a corresponding docs pull request in the github/codeql repo and add the ready-for-doc-review label there.

When results were already cached in memory and the view requested the
result, it would not be loaded because the event would not be fired.
This fires the event when the result is loaded from cache as well, to
ensure that the view always receives the result.
@koesie10 koesie10 requested a review from a team as a code owner November 29, 2022 13:28
createCacheKey(variantAnalysisId, repositoryFullName),
);
if (result) {
this._onResultLoaded.fire(result);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need to do this in the next if statement as well?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We shouldn't need to do that, that should already be handled in the loadResultsIntoMemory method:

Copy link
Copy Markdown
Contributor

@elenatanasoiu elenatanasoiu Nov 29, 2022

Choose a reason for hiding this comment

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

Yup, but the next if statement is actually calling loadResultsFromStorage instead of loadResultsIntoMemory:

if (options?.skipCacheStore) {
  return this.loadResultsFromStorage(
    variantAnalysisId,
    variantAnalysisStoragePath,
    repositoryFullName,
  );
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That's true, but that if-statement is explicitly created to skip storing the results anywhere, which should include not firing the event. If we did fire the event in there, it would distribute the result to the view, which would then store it in memory. By setting the skipCacheStore option, the caller is explicitly saying that they don't want the result to be stored anywhere.

This option is used when exporting results. For example, if there are 1,000 results, you might want to export all 1,000 results to a file. We need to load the SARIF files into memory to create the Markdown files, but this is very temporary. Let's say the SARIF file results in a memory usage of 30MB. Then, we'd use 30MB while exporting, and return to the previous memory usage once exporting is done. If this option is not set, we'd use 30,000 MB (30 GB) after exporting since every result is stored in cache.

If we were to now change the behaviour to fire the event, we would still be storing that 30 GB of memory in the view, rather than in the extension host. I don't think this is what we want to do.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I love the example! :) Thanks! That makes sense.

@elenatanasoiu
Copy link
Copy Markdown
Contributor

Would you be up for writing a test for this as well? It would involve listing the three cases:

  • result already exists, make sure it's loaded
  • result doesn't exist
    • the skipCacheStore option is on: make sure it loads results into memory and does create a cache key
    • the skipCacheStore option is off: make sure it loads results into memory and creates a cache key

@koesie10
Copy link
Copy Markdown
Member Author

Would you be up for writing a test for this as well? It would involve listing the three cases:

Sure, I should be able to write some simple tests for this. Since the Jest migration is not yet merged into main (since it's still waiting on #1801), I'm a bit hesitant to start on it now since this will probably involve quite a lot of stubbing (we need to either load results from the filesystem or stub the loadResultsFromStorage method).

@elenatanasoiu
Copy link
Copy Markdown
Contributor

Ah, right. Perhaps a ticket for later then?

@koesie10
Copy link
Copy Markdown
Member Author

Ah, right. Perhaps a ticket for later then?

I've created a ticket for this, see the internal linked issue.

@koesie10 koesie10 merged commit ec9d6b1 into main Nov 29, 2022
@koesie10 koesie10 deleted the koesie10/fix-loading-results branch November 29, 2022 15:30
@koesie10 koesie10 mentioned this pull request Nov 30, 2022
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants