From a62a1757682cee2f8690f67f3b2a63e8a254ebd5 Mon Sep 17 00:00:00 2001 From: Hunternif Date: Sun, 7 Apr 2019 19:44:27 +0700 Subject: [PATCH 1/5] Prevent caching when searching random --- server/szurubooru/search/executor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From 0808fa850f255e8d4099c8c1cee867aa67e2f8f6 Mon Sep 17 00:00:00 2001 From: Hunternif Date: Sun, 7 Apr 2019 22:32:39 +0700 Subject: [PATCH 2/5] add randomize button --- client/html/posts_header.tpl | 2 ++ client/js/views/posts_header_view.js | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/client/html/posts_header.tpl b/client/html/posts_header.tpl index e0ba0eae..61f03c72 100644 --- a/client/html/posts_header.tpl +++ b/client/html/posts_header.tpl @@ -4,6 +4,8 @@ %><% %><% %><% + %><% + %><% %><% if (ctx.enableSafety) { %><% %>'/><% %>'/><% diff --git a/client/js/views/posts_header_view.js b/client/js/views/posts_header_view.js index 6b697c4f..b0ddf5ce 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,14 @@ class PostsHeaderView extends events.EventTarget { e.preventDefault(); this._navigate(); } + _evtRandomButtonClick(e) { + if (!this._queryInputNode.value.includes('sort:random')) { + this._queryInputNode.value += ' sort:random'; + } else { + location.reload(); + } + this._navigate(); + } _navigate() { this._autoCompleteControl.hide(); From 1032104f886623f772ac22803692ab393af86b49 Mon Sep 17 00:00:00 2001 From: Hunternif Date: Tue, 9 Apr 2019 00:17:21 +0700 Subject: [PATCH 3/5] Fix alignment on random button --- client/html/posts_header.tpl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/html/posts_header.tpl b/client/html/posts_header.tpl index 61f03c72..69a07911 100644 --- a/client/html/posts_header.tpl +++ b/client/html/posts_header.tpl @@ -4,8 +4,9 @@ %><% %><% %><% - %><% - %><% + %><% %><% if (ctx.enableSafety) { %><% %>'/><% %>'/><% From 86d0c4086bb43dad4655a41e34e5ad0c969dbb21 Mon Sep 17 00:00:00 2001 From: Hunternif Date: Tue, 9 Apr 2019 01:47:01 +0700 Subject: [PATCH 4/5] Don't cache urls with 'sort:random'. No need to refresh the page for the same url now. --- client/js/models/post_list.js | 5 +++++ client/js/views/posts_header_view.js | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/client/js/models/post_list.js b/client/js/models/post_list.js index 74f089f3..57a7d841 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.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 b0ddf5ce..2daf32d4 100644 --- a/client/js/views/posts_header_view.js +++ b/client/js/views/posts_header_view.js @@ -248,10 +248,9 @@ class PostsHeaderView extends events.EventTarget { this._navigate(); } _evtRandomButtonClick(e) { + e.preventDefault(); if (!this._queryInputNode.value.includes('sort:random')) { this._queryInputNode.value += ' sort:random'; - } else { - location.reload(); } this._navigate(); } From 5d96e0e7870e07642c0e7fe34859baae071d4dc2 Mon Sep 17 00:00:00 2001 From: Hunternif Date: Tue, 9 Apr 2019 02:27:51 +0700 Subject: [PATCH 5/5] Null check --- client/js/models/post_list.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/js/models/post_list.js b/client/js/models/post_list.js index 57a7d841..80bd41ee 100644 --- a/client/js/models/post_list.js +++ b/client/js/models/post_list.js @@ -18,7 +18,7 @@ class PostList extends AbstractList { static search(text, offset, limit, fields) { //For queries with random sorting, bypass cache by appending random number - let cache = text.includes('sort:random') + let cache = text != null && text.includes('sort:random') ? Math.round(Math.random() * 1000) : 0; return api.get(