From 7a79fed828c73b61d3e8c5504773e79fe231c063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Fri, 11 Aug 2023 20:43:56 -0400 Subject: [PATCH] feat: closes #11902, ability to clear search history --- public/language/en-GB/admin/dashboard.json | 4 ++- public/src/admin/dashboard/searches.js | 22 +++++++++++++++ src/database/redis/main.js | 2 +- src/socket.io/admin.js | 9 +++++++ src/views/admin/dashboard/searches.tpl | 31 +++++++++++----------- 5 files changed, 51 insertions(+), 17 deletions(-) create mode 100644 public/src/admin/dashboard/searches.js diff --git a/public/language/en-GB/admin/dashboard.json b/public/language/en-GB/admin/dashboard.json index c75f2d68ac..681c202f47 100644 --- a/public/language/en-GB/admin/dashboard.json +++ b/public/language/en-GB/admin/dashboard.json @@ -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?" } diff --git a/public/src/admin/dashboard/searches.js b/public/src/admin/dashboard/searches.js new file mode 100644 index 0000000000..8e53847b64 --- /dev/null +++ b/public/src/admin/dashboard/searches.js @@ -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; +}); diff --git a/src/database/redis/main.js b/src/database/redis/main.js index c2e030b42c..8b79afb07c 100644 --- a/src/database/redis/main.js +++ b/src/database/redis/main.js @@ -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); diff --git a/src/socket.io/admin.js b/src/socket.io/admin.js index 21165713db..e5efe90482 100644 --- a/src/socket.io/admin.js +++ b/src/socket.io/admin.js @@ -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); diff --git a/src/views/admin/dashboard/searches.tpl b/src/views/admin/dashboard/searches.tpl index 27bf1ca11d..c669c4eda4 100644 --- a/src/views/admin/dashboard/searches.tpl +++ b/src/views/admin/dashboard/searches.tpl @@ -1,20 +1,21 @@
- -
-
- - -
-
- - -
-
- -
-
- +
+
+
+ + +
+
+ + +
+
+ +
+
+ +