🎨 SourceIterator is not sized anymore

This commit is contained in:
GeoffreyCoulaud
2023-05-31 18:18:58 +02:00
parent ef63210a8f
commit a213abe4da
3 changed files with 2 additions and 26 deletions

View File

@@ -16,17 +16,6 @@ class LutrisSourceIterator(SourceIterator):
db_connection = None db_connection = None
db_cursor = None db_cursor = None
db_location = None db_location = None
db_len_request = """
SELECT count(*)
FROM 'games'
WHERE
name IS NOT NULL
AND slug IS NOT NULL
AND configPath IS NOT NULL
AND installed
AND (runner IS NOT "steam" OR :import_steam)
;
"""
db_games_request = """ db_games_request = """
SELECT id, name, slug, runner, hidden SELECT id, name, slug, runner, hidden
FROM 'games' FROM 'games'
@@ -46,16 +35,10 @@ class LutrisSourceIterator(SourceIterator):
self.db_location = self.source.location / "pga.db" self.db_location = self.source.location / "pga.db"
self.db_connection = connect(self.db_location) self.db_connection = connect(self.db_location)
self.db_request_params = {"import_steam": self.import_steam} self.db_request_params = {"import_steam": self.import_steam}
self.__len__() # Init iterator length
self.db_cursor = self.db_connection.execute( self.db_cursor = self.db_connection.execute(
self.db_games_request, self.db_request_params self.db_games_request, self.db_request_params
) )
@lru_cache(maxsize=1)
def __len__(self):
cursor = self.db_connection.execute(self.db_len_request, self.db_request_params)
return cursor.fetchone()[0]
def __next__(self): def __next__(self):
"""Produce games""" """Produce games"""

View File

@@ -1,11 +1,11 @@
from abc import abstractmethod from abc import abstractmethod
from collections.abc import Iterable, Iterator, Sized from collections.abc import Iterable, Iterator
from typing import Optional from typing import Optional
from src.game import Game from src.game import Game
class SourceIterator(Iterator, Sized): class SourceIterator(Iterator):
"""Data producer for a source of games""" """Data producer for a source of games"""
source: "Source" = None source: "Source" = None
@@ -17,10 +17,6 @@ class SourceIterator(Iterator, Sized):
def __iter__(self) -> "SourceIterator": def __iter__(self) -> "SourceIterator":
return self return self
@abstractmethod
def __len__(self) -> int:
"""Get a rough estimate of the number of games produced by the source"""
@abstractmethod @abstractmethod
def __next__(self) -> Optional[Game]: def __next__(self) -> Optional[Game]:
"""Get the next generated game from the source. """Get the next generated game from the source.

View File

@@ -51,9 +51,6 @@ class SteamSourceIterator(SourceIterator):
self.manifests_iterator = iter(self.manifests) self.manifests_iterator = iter(self.manifests)
def __len__(self):
return len(self.manifests)
def __next__(self): def __next__(self):
"""Produce games""" """Produce games"""