Skip to content

Commit

Permalink
🔀 Added true_random sort that don't keep server-side cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Lugrim authored and Soblow committed Dec 26, 2023
1 parent b7b1065 commit c7704a5
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 @@ -412,7 +412,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 @@ -89,12 +89,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 c7704a5

Please sign in to comment.