mirror of
https://github.com/ArchipelagoMW/Archipelago.git
synced 2026-03-26 02:13:19 -07:00
Create a new class that handles conversion worlds+embedded -> context data. Create a derived class that uses static_server_data+pony instead. There is also a not very efficient feature to deduplicate strings (may need perf testing). By moving code around, we can simplify a lot of the world loading. Where code lines were touched, some typing and some reformatting was added. The back compat for GetDataPackage without games was finally dropped. This was done as a cleanup because the refactoring touched those lines anyway. Also reworked the per-context dicts and the RoomInfo to hopefully be more efficient by ignoring unused games. (Generating the list of used games was required for the new code anyway.) Side effect of the MultiServer cache: we now load worlds lazily (but still all at once) and don't modify the games package in place. If needed we create copies. This almost gets us to the point where MultiServer doesn't need worlds - it still needs them for the forbidden items. There is a bonus optimization that deduplicates strings in name_groups that may have bad performance and may need some perf testing if we run into issues.
33 lines
1.5 KiB
Python
33 lines
1.5 KiB
Python
import typing as t
|
|
|
|
from NetUtils import GamesPackage
|
|
from Utils import restricted_loads
|
|
from WebHostLib.models import GameDataPackage
|
|
from apmw.multiserver.gamespackage.cache import GamesPackageCache, ItemNameGroups, LocationNameGroups
|
|
|
|
|
|
class DBGamesPackageCache(GamesPackageCache):
|
|
_static: dict[str, tuple[GamesPackage, ItemNameGroups, LocationNameGroups]]
|
|
|
|
def __init__(self, static_games_package: dict[str, GamesPackage]) -> None:
|
|
super().__init__()
|
|
self._static = {game: super().get(game, games_package) for game, games_package in static_games_package.items()}
|
|
|
|
def get(
|
|
self,
|
|
game: str,
|
|
full_games_package: GamesPackage,
|
|
) -> tuple[GamesPackage, ItemNameGroups, LocationNameGroups]:
|
|
# for games started on webhost, full_games_package is likely unpopulated and only has the checksum field
|
|
cache_key = (game, full_games_package.get("checksum", None))
|
|
cached = self._get(cache_key)
|
|
if any(value is None for value in cached):
|
|
row = GameDataPackage.get(checksum=full_games_package["checksum"])
|
|
if row: # None if rolled on >= 0.3.9 but uploaded to <= 0.3.8 ...
|
|
return super().get(game, restricted_loads(row.data))
|
|
return super().get(game, full_games_package) # ... in which case full_games_package should be populated
|
|
return t.cast(tuple[GamesPackage, ItemNameGroups, LocationNameGroups], cached)
|
|
|
|
def get_static(self, game: str) -> tuple[GamesPackage, ItemNameGroups, LocationNameGroups]:
|
|
return self._static[game]
|