|
32 | 32 | ) |
33 | 33 | from dataclasses import dataclass |
34 | 34 | from datetime import date |
35 | | -from multiprocessing import Value |
36 | 35 | from typing import Any, Final, Literal, cast |
37 | 36 | from urllib.parse import urlencode |
38 | 37 |
|
@@ -81,9 +80,6 @@ class UltraDictType[K, V](MutableMapping[K, V], abc.ABC): |
81 | 80 | UltraDict(buffer_size=1024**2, serializer=dill) |
82 | 81 | ) |
83 | 82 |
|
84 | | -MAX_QUOTES_ID = Value("Q", 0) |
85 | | -MAX_AUTHORS_ID = Value("Q", 0) |
86 | | - |
87 | 83 |
|
88 | 84 | @dataclass(init=False, slots=True) |
89 | 85 | class QuotesObjBase(abc.ABC): |
@@ -437,7 +433,6 @@ def parse_author(json_data: Mapping[str, Any]) -> Author: |
437 | 433 | if author is None: |
438 | 434 | # pylint: disable-next=too-many-function-args |
439 | 435 | author = Author(id_, name, None) |
440 | | - MAX_AUTHORS_ID.value = max(MAX_AUTHORS_ID.value, id_) |
441 | 436 | elif author.name != name: |
442 | 437 | author.name = name |
443 | 438 | author.info = None # reset info |
@@ -474,7 +469,6 @@ def parse_quote( |
474 | 469 | if quote is None: # new quote |
475 | 470 | # pylint: disable=too-many-function-args |
476 | 471 | quote = Quote(quote_id, quote_str, author.id) |
477 | | - MAX_QUOTES_ID.value = max(MAX_QUOTES_ID.value, quote.id) |
478 | 472 | else: # quote was already saved |
479 | 473 | quote.quote = quote_str |
480 | 474 | quote.author_id = author.id |
@@ -795,12 +789,12 @@ async def get_rating_by_id(quote_id: int, author_id: int) -> int | None: |
795 | 789 |
|
796 | 790 | def get_random_quote_id() -> int: |
797 | 791 | """Get random quote id.""" |
798 | | - return random.randint(1, MAX_QUOTES_ID.value) # nosec: B311 |
| 792 | + return random.choice(tuple(QUOTES_CACHE)) |
799 | 793 |
|
800 | 794 |
|
801 | 795 | def get_random_author_id() -> int: |
802 | 796 | """Get random author id.""" |
803 | | - return random.randint(1, MAX_AUTHORS_ID.value) # nosec: B311 |
| 797 | + return random.choice(tuple(AUTHORS_CACHE)) |
804 | 798 |
|
805 | 799 |
|
806 | 800 | def get_random_id() -> tuple[int, int]: |
|
0 commit comments