Remove OrderedSet, channels have to be re-sorted during selection process anyway
This commit is contained in:
1 parent
b3516d5658
commit
1dd31e3f93
2 files changed
+5
-45
No files matched your search
@@ -36,7 +36,6 @@ from utils import (
|
|||||||
timestamp,
|
timestamp,
|
||||||
create_nonce,
|
create_nonce,
|
||||||
task_wrapper,
|
task_wrapper,
|
||||||
OrderedSet,
|
|
||||||
AwaitableValue,
|
AwaitableValue,
|
||||||
ExponentialBackoff,
|
ExponentialBackoff,
|
||||||
)
|
)
|
||||||
@@ -724,14 +723,14 @@ class Twitch:
|
|||||||
elif self._state is State.CHANNELS_FETCH:
|
elif self._state is State.CHANNELS_FETCH:
|
||||||
self.gui.status.update(_("gui", "status", "gathering"))
|
self.gui.status.update(_("gui", "status", "gathering"))
|
||||||
# start with all current channels, clear the memory and GUI
|
# start with all current channels, clear the memory and GUI
|
||||||
new_channels: OrderedSet[Channel] = OrderedSet(channels.values())
|
new_channels: set[Channel] = set(channels.values())
|
||||||
channels.clear()
|
channels.clear()
|
||||||
self.gui.channels.clear()
|
self.gui.channels.clear()
|
||||||
# gather and add ACL channels from campaigns
|
# gather and add ACL channels from campaigns
|
||||||
# NOTE: we consider only campaigns that can be progressed
|
# NOTE: we consider only campaigns that can be progressed
|
||||||
# NOTE: we use another set so that we can set them online separately
|
# NOTE: we use another set so that we can set them online separately
|
||||||
no_acl: set[Game] = set()
|
no_acl: set[Game] = set()
|
||||||
acl_channels: OrderedSet[Channel] = OrderedSet()
|
acl_channels: set[Channel] = set()
|
||||||
next_hour = datetime.now(timezone.utc) + timedelta(hours=1)
|
next_hour = datetime.now(timezone.utc) + timedelta(hours=1)
|
||||||
for campaign in self.inventory:
|
for campaign in self.inventory:
|
||||||
if (
|
if (
|
||||||
@@ -757,7 +756,8 @@ class Twitch:
|
|||||||
# add a list of live channels with drops enabled
|
# add a list of live channels with drops enabled
|
||||||
new_channels.update(await self.get_live_streams(game, drops_enabled=True))
|
new_channels.update(await self.get_live_streams(game, drops_enabled=True))
|
||||||
# sort them descending by viewers, by priority and by game priority
|
# sort them descending by viewers, by priority and by game priority
|
||||||
# NOTE: We can drop OrderedSet now because there's no more channels being added
|
# NOTE: Viewers sort also ensures ONLINE channels are sorted to the top
|
||||||
|
# NOTE: We can drop using the set now, because there's no more channels being added
|
||||||
ordered_channels: list[Channel] = sorted(
|
ordered_channels: list[Channel] = sorted(
|
||||||
new_channels, key=self._viewers_key, reverse=True
|
new_channels, key=self._viewers_key, reverse=True
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ from contextlib import suppress
|
|||||||
from functools import cached_property
|
from functools import cached_property
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from collections import abc, OrderedDict
|
from collections import abc, OrderedDict
|
||||||
from typing import Any, Literal, MutableSet, Callable, Generic, Mapping, TypeVar, ParamSpec, cast
|
from typing import Any, Literal, Callable, Generic, Mapping, TypeVar, ParamSpec, cast
|
||||||
|
|
||||||
import yarl
|
import yarl
|
||||||
from PIL.ImageTk import PhotoImage
|
from PIL.ImageTk import PhotoImage
|
||||||
@@ -327,46 +327,6 @@ class ExponentialBackoff:
|
|||||||
self.steps = 0
|
self.steps = 0
|
||||||
|
|
||||||
|
|
||||||
class OrderedSet(MutableSet[_T]):
|
|
||||||
"""
|
|
||||||
Implementation of a set that preserves insertion order,
|
|
||||||
based on OrderedDict with values set to None.
|
|
||||||
"""
|
|
||||||
def __init__(self, iterable: abc.Iterable[_T] = [], /):
|
|
||||||
self._items: OrderedDict[_T, None] = OrderedDict((item, None) for item in iterable)
|
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
|
||||||
return f"{self.__class__.__name__}([{', '.join(map(repr, self._items))}])"
|
|
||||||
|
|
||||||
def __contains__(self, item: object, /) -> bool:
|
|
||||||
return item in self._items
|
|
||||||
|
|
||||||
def __iter__(self) -> abc.Iterator[_T]:
|
|
||||||
return iter(self._items)
|
|
||||||
|
|
||||||
def __len__(self) -> int:
|
|
||||||
return len(self._items)
|
|
||||||
|
|
||||||
def add(self, item: _T, /) -> None:
|
|
||||||
self._items[item] = None
|
|
||||||
|
|
||||||
def discard(self, item: _T, /) -> None:
|
|
||||||
with suppress(KeyError):
|
|
||||||
del self._items[item]
|
|
||||||
|
|
||||||
def update(self, *others: abc.Iterable[_T]) -> None:
|
|
||||||
for it in others:
|
|
||||||
for item in it:
|
|
||||||
if item not in self._items:
|
|
||||||
self._items[item] = None
|
|
||||||
|
|
||||||
def difference_update(self, *others: abc.Iterable[_T]) -> None:
|
|
||||||
for it in others:
|
|
||||||
for item in it:
|
|
||||||
if item in self._items:
|
|
||||||
del self._items[item]
|
|
||||||
|
|
||||||
|
|
||||||
class AwaitableValue(Generic[_T]):
|
class AwaitableValue(Generic[_T]):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._value: _T
|
self._value: _T
|
||||||
|
|||||||
Reference in new issue
Block a user