Fix loading results in second opened view#1806
Conversation
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.
| createCacheKey(variantAnalysisId, repositoryFullName), | ||
| ); | ||
| if (result) { | ||
| this._onResultLoaded.fire(result); |
There was a problem hiding this comment.
Do we need to do this in the next if statement as well?
There was a problem hiding this comment.
We shouldn't need to do that, that should already be handled in the loadResultsIntoMemory method:
There was a problem hiding this comment.
Yup, but the next if statement is actually calling loadResultsFromStorage instead of loadResultsIntoMemory:
if (options?.skipCacheStore) {
return this.loadResultsFromStorage(
variantAnalysisId,
variantAnalysisStoragePath,
repositoryFullName,
);
}There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I love the example! :) Thanks! That makes sense.
|
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 |
|
Ah, right. Perhaps a ticket for later then? |
I've created a ticket for this, see the internal linked issue. |
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
ready-for-doc-reviewlabel there.