Skip to content

Commit

Permalink
🔀 Added true_random sort that don't keep cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Lugrim committed Nov 5, 2023
1 parent d97ada8 commit d0d6d0b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion server/szurubooru/search/configs/post_search_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def sort_columns(self) -> Dict[str, Tuple[SaColumn, str]]:
return util.unalias_dict(
[
(
["random"],
["random", "true_random"],
(sa.sql.expression.func.random(), self.SORT_NONE),
),
(["id"], (model.Post.post_id, self.SORT_DESC)),
Expand Down
7 changes: 5 additions & 2 deletions server/szurubooru/search/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,15 @@ def execute(
offset = 0

disable_eager_loads = False
disable_cache = False
for token in search_query.sort_tokens:
if token.name == "random":
if "random" in token.name:
disable_eager_loads = True
if token.name == "true_random":
disable_cache = True

key = (id(self.config), hash(search_query), offset, limit)
if cache.has(key):
if not disable_cache and cache.has(key):
return cache.get(key)

filter_query = self.config.create_filter_query(disable_eager_loads)
Expand Down

0 comments on commit d0d6d0b

Please sign in to comment.