diff --git a/client/html/posts_header.tpl b/client/html/posts_header.tpl index e0ba0eae..69a07911 100644 --- a/client/html/posts_header.tpl +++ b/client/html/posts_header.tpl @@ -4,6 +4,9 @@ %><% %><% %><% + %><% %><% if (ctx.enableSafety) { %><% %>'/><% %>'/><% diff --git a/client/js/models/post_list.js b/client/js/models/post_list.js index 74f089f3..80bd41ee 100644 --- a/client/js/models/post_list.js +++ b/client/js/models/post_list.js @@ -17,6 +17,10 @@ class PostList extends AbstractList { } static search(text, offset, limit, fields) { + //For queries with random sorting, bypass cache by appending random number + let cache = text != null && text.includes('sort:random') + ? Math.round(Math.random() * 1000) + : 0; return api.get( uri.formatApiLink( 'posts', { @@ -24,6 +28,7 @@ class PostList extends AbstractList { offset: offset, limit: limit, fields: fields.join(','), + cache: cache, })) .then(response => { return Promise.resolve(Object.assign( diff --git a/client/js/views/posts_header_view.js b/client/js/views/posts_header_view.js index 9ba09c91..2c5997ba 100644 --- a/client/js/views/posts_header_view.js +++ b/client/js/views/posts_header_view.js @@ -145,6 +145,7 @@ class PostsHeaderView extends events.EventTarget { 'click', e => this._evtSafetyButtonClick(e)); } this._formNode.addEventListener('submit', e => this._evtFormSubmit(e)); + this._randomButtonNode.addEventListener('click', e => this._evtRandomButtonClick(e)); this._bulkEditors = []; if (this._bulkEditTagsNode) { @@ -191,6 +192,10 @@ class PostsHeaderView extends events.EventTarget { return this._hostNode.querySelector('form [name=search-text]'); } + get _randomButtonNode() { + return this._hostNode.querySelector('#random-button'); + } + get _bulkEditTagsNode() { return this._hostNode.querySelector('.bulk-edit-tags'); } @@ -242,6 +247,13 @@ class PostsHeaderView extends events.EventTarget { e.preventDefault(); this._navigate(); } + _evtRandomButtonClick(e) { + e.preventDefault(); + if (!this._queryInputNode.value.includes('sort:random')) { + this._queryInputNode.value += ' sort:random'; + } + this._navigate(); + } _navigate() { this._autoCompleteControl.hide(); diff --git a/server/szurubooru/search/executor.py b/server/szurubooru/search/executor.py index 10b34b1c..d5f43b0a 100644 --- a/server/szurubooru/search/executor.py +++ b/server/szurubooru/search/executor.py @@ -94,7 +94,7 @@ class Executor: disable_eager_loads = True key = (id(self.config), hash(search_query), offset, limit) - if cache.has(key): + if not disable_eager_loads and cache.has(key): return cache.get(key) filter_query = self.config.create_filter_query(disable_eager_loads)