This commit is contained in:
Hunternif 2020-05-02 09:43:02 +07:00 committed by GitHub
commit 95d3ebd4af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 1 deletions

View file

@ -4,6 +4,9 @@
%><wbr/><%
%><input class='mousetrap' type='submit' value='Search'/><%
%><wbr/><%
%><button id="random-button" style="padding:0.2em; margin-right:0.25em; margin-bottom:0.25em;"><%
%><i class="fa fa-random" style="vertical-align: middle"><%
%></button><%
%><% if (ctx.enableSafety) { %><%
%><input data-safety=safe type='button' class='mousetrap safety safety-safe <%- ctx.settings.listPosts.safe ? '' : 'disabled' %>'/><%
%><input data-safety=sketchy type='button' class='mousetrap safety safety-sketchy <%- ctx.settings.listPosts.sketchy ? '' : 'disabled' %>'/><%

View file

@ -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(

View file

@ -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();

View file

@ -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)