roblox-plus / extension

This is the source of the Roblox+ Google Chrome extension!
https://roblox.plus
46 stars 37 forks source link

Add locks to message listener #69

Closed WebGL3D closed 1 year ago

WebGL3D commented 1 year ago

What :lock:

With #66, we introduced a localizationService, so that the feature that adds a "trade" link on the group wall posts of the Trade. group has translated text.

With this though, because multiple wall posts would get processed in parallel, it lead to multiple requests to the locale + translations API. To combat this, we introduced a cache, and then preloaded the translations, so the cache was hydrated. This was inefficient because it meant we would always load translation resources, even if we didn't need them.

Solution :bulb:

Following the advice found on stackoverflow, we are now using the navigator.locks API. This API allows us to take out a lock and ensure that multiple requests for translation resources don't get processed at the same time.

We have implemented this into the messageService as levelOfParallelism, where we allow it to be set to 1 to ensure only one message can be processed in parallel. -1 disables this option (allowing unlimited messages to be processed in parallel. The reason for this implementation is that it allows us to change the implementation of the messageService later, and add an actual level of parallelism feature. But for now, this suites the use case.

Unrelated :see_no_evil:

As part of this review, we found more code referencing sponsored items, which were removed with #67. We removed more code relating to this as a result of the extension not starting without doing this.

Also removed the .vscode task that was still there to compile scss, which is no longer relevant.