mirror of
https://github.com/ArchipelagoMW/Archipelago.git
synced 2026-03-22 15:45:04 -07:00
customserver: make WebHost import lazy in games package cache
and fix test
This commit is contained in:
@@ -2,8 +2,6 @@ from NetUtils import GamesPackage
|
||||
from Utils import restricted_loads
|
||||
from apmw.multiserver.gamespackage.cache import GamesPackageCache, ItemNameGroups, LocationNameGroups
|
||||
|
||||
from WebHostLib.models import GameDataPackage
|
||||
|
||||
|
||||
class DBGamesPackageCache(GamesPackageCache):
|
||||
_static: dict[str, tuple[GamesPackage, ItemNameGroups, LocationNameGroups]]
|
||||
@@ -22,11 +20,15 @@ class DBGamesPackageCache(GamesPackageCache):
|
||||
cached = self._get(cache_key)
|
||||
if any(value is None for value in cached):
|
||||
if "checksum" not in full_games_package:
|
||||
return super().get(game, full_games_package) # predates checksum, assume fully populated
|
||||
return super().get(game, full_games_package) # no checksum, assume fully populated
|
||||
|
||||
from WebHostLib.models import GameDataPackage
|
||||
|
||||
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 cached # type: ignore # mypy doesn't understand any value is None
|
||||
|
||||
def get_static(self, game: str) -> tuple[GamesPackage, ItemNameGroups, LocationNameGroups]:
|
||||
|
||||
@@ -5,8 +5,6 @@ from test.multiserver.test_gamespackage_cache import GamesPackageCacheTest
|
||||
|
||||
import Utils
|
||||
from NetUtils import GamesPackage
|
||||
|
||||
import apmw.webhost.customserver.gamespackage.cache
|
||||
from apmw.webhost.customserver.gamespackage.cache import DBGamesPackageCache
|
||||
|
||||
|
||||
@@ -37,15 +35,23 @@ class DBGamesPackageCacheTest(GamesPackageCacheTest):
|
||||
"checksum": "2345",
|
||||
}
|
||||
}
|
||||
orig_db_type: t.Any
|
||||
orig_db_type: t.ClassVar[type]
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls) -> None:
|
||||
import WebHostLib.models
|
||||
|
||||
cls.orig_db_type = WebHostLib.models.GameDataPackage
|
||||
WebHostLib.models.GameDataPackage = FakeGameDataPackage # type: ignore
|
||||
|
||||
def setUp(self) -> None:
|
||||
self.orig_db_type = apmw.webhost.customserver.gamespackage.cache.GameDataPackage # type: ignore[attr-defined]
|
||||
self.cache = DBGamesPackageCache(self.static_data)
|
||||
apmw.webhost.customserver.gamespackage.cache.GameDataPackage = FakeGameDataPackage # type: ignore
|
||||
|
||||
def tearDown(self) -> None:
|
||||
apmw.webhost.customserver.gamespackage.cache.GameDataPackage = self.orig_db_type # type: ignore[attr-defined]
|
||||
@classmethod
|
||||
def tearDownClass(cls) -> None:
|
||||
import WebHostLib.models
|
||||
|
||||
WebHostLib.models.GameDataPackage = cls.orig_db_type # type: ignore
|
||||
|
||||
def assert_conversion(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user