Fix duplicated addons in my addons page #1443
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm not sure if there is an issue for this on this repository, but I have previously opened one on WowUp.CF repository.
Closing WowUp/WowUp.CF#60
Explanation of the bug
The bug appears on first loading of the app when there is no electron-store saved in user app data.
The app is calling 3 times
AddonStorageService.saveAll()
fromAddonService.rescanInstallation()
fromAddonService.getAddons()
fromMyAddonsComponent.loadAddons()
.2 times by this
switchMap
:Because
autoUpdateComplete
is aBehaviorSubject
so it emits it's firstValue0
then whenSessionService.autoUpdateComplete()
is called.1 time inside
MyAddonsComponent.lazyLoad()
.AddonService.rescanInstallation()
is called 3 times rapidly and because it's a Promise, it's beginning each call without waiting for the other one to finish.From a UI perspective, we are updating only with one result from
MyAddonsComponent.loadAddons()
so we are not seeing any problem.But the
handle
ofIPC_ADDONS_SAVE_ALL
inipc-events.ts
is not clearing the store, it can have 3 times the same addon in the store.So when the user relaunches the application or clicks on
PAGES.MY_ADDONS.CHECK_UPDATES_BUTTON_TOOLTIP
button and getting the addons from the store, it shows the addons duplicated.Explanation of my fix
It's working because
IPC_ADDONS_SAVE_ALL
is only called fromAddonStorage.saveAll()
which is only called fromAddonService.rescanInstallation()
so it has all the addons from the disk and it's not losing any data.But a better fix would be to either :
MyAddonsComponent.loadAddons()
AddonService.rescanInstallation()
if one is already in progressTesting the behavior
To test the problematic behavior, before launching the application, you should delete
addons.json
from yourAppData\Roaming\WowUp
folder, because it's the file stored byelectron-store
to save the store between relaunch of the app.The bug is not happening every time because it will depend on the speed of
AddonService.rescanInstallation()
to finish.