feat: closes #11902, ability to clear search history

isekai-main
Barış Soner Uşaklı 1 year ago
parent e151ec86cc
commit 7a79fed828

@ -92,5 +92,7 @@
"end": "End",
"filter": "Filter",
"view-as-json": "View as JSON",
"expand-analytics": "Expand analytics"
"expand-analytics": "Expand analytics",
"clear-search-history": "Clear Search History",
"clear-search-history-confirm": "Are you sure you want to clear entire search history?"
}

@ -0,0 +1,22 @@
'use strict';
define('admin/dashboard/searches', ['alerts', 'bootbox'], (alerts, bootbox) => {
const ACP = {};
ACP.init = () => {
$('#clear-search-history').on('click', () => {
bootbox.confirm('[[admin/dashboard:clear-search-history-confirm]]', function (ok) {
if (ok) {
socket.emit('admin.clearSearchHistory', function (err) {
if (err) {
return alerts.error(err);
}
ajaxify.refresh();
});
}
});
});
};
return ACP;
});

@ -26,7 +26,7 @@ module.exports = function (module) {
module.scan = async function (params) {
let cursor = '0';
let returnData = [];
const seen = {};
const seen = Object.create(null);
do {
/* eslint-disable no-await-in-loop */
const res = await module.client.scan(cursor, 'MATCH', params.match, 'COUNT', 10000);

@ -8,6 +8,7 @@ const events = require('../events');
const db = require('../database');
const privileges = require('../privileges');
const websockets = require('./index');
const batch = require('../batch');
const index = require('./index');
const getAdminSearchDict = require('../admin/search').getDictionary;
@ -117,4 +118,12 @@ SocketAdmin.getServerTime = function (socket, data, callback) {
});
};
SocketAdmin.clearSearchHistory = async function () {
const keys = await db.scan({ match: 'searches:*' });
await batch.processArray(keys, db.deleteAll, {
batch: 500,
interval: 0,
});
};
require('../promisify')(SocketAdmin);

@ -1,20 +1,21 @@
<div class="row dashboard px-lg-4">
<div class="col-12">
<form class="d-flex flex-wrap gap-3 align-sm-items-center mb-3" method="GET">
<div class="d-flex align-items-center gap-2">
<label class="form-label mb-0" for="start">[[admin/dashboard:start]]</label>
<input type="date" class="form-control form-control-sm w-auto" id="start" name="start" value="{startDate}">
</div>
<div class="d-flex align-items-center gap-2">
<label class="form-label mb-0" for="end">[[admin/dashboard:end]]</label>
<input type="date" class="form-control form-control-sm w-auto" id="end" name="end" value="{endDate}">
</div>
<div class="">
<button onclick="$('form').submit();return false;"class="btn btn-primary btn-sm" type="submit">[[admin/dashboard:filter]]</button>
</div>
</form>
<div class="d-flex justify-content-between align-items-center mb-3">
<form class="d-flex flex-wrap gap-3 align-sm-items-center" method="GET">
<div class="d-flex align-items-center gap-2">
<label class="form-label mb-0" for="start">[[admin/dashboard:start]]</label>
<input type="date" class="form-control form-control-sm w-auto" id="start" name="start" value="{startDate}">
</div>
<div class="d-flex align-items-center gap-2">
<label class="form-label mb-0" for="end">[[admin/dashboard:end]]</label>
<input type="date" class="form-control form-control-sm w-auto" id="end" name="end" value="{endDate}">
</div>
<div class="">
<button onclick="$('form').submit();return false;"class="btn btn-primary btn-sm" type="submit">[[admin/dashboard:filter]]</button>
</div>
</form>
<button id="clear-search-history" class="btn btn-sm btn-light"><i class="fa fa-trash text-danger"></i> [[admin/dashboard:clear-search-history]]</button>
</div>
<table class="table table-sm text-sm search-list">
<thead>

Loading…
Cancel
Save