mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-09-01 04:46:26 +02:00
Zscan (#8458)
* feat: zscan * fix: mongodb tests * feat: scan, ip search starts with
This commit is contained in:
committed by
GitHub
parent
be85123ad5
commit
e95cd28f6f
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var helpers = module.exports;
|
||||
const helpers = module.exports;
|
||||
const utils = require('../../utils');
|
||||
|
||||
helpers.noop = function () {};
|
||||
|
||||
@@ -48,3 +49,21 @@ helpers.deserializeData = function (data) {
|
||||
helpers.valueToString = function (value) {
|
||||
return String(value);
|
||||
};
|
||||
|
||||
helpers.buildMatchQuery = function (match) {
|
||||
let _match = match;
|
||||
if (match.startsWith('*')) {
|
||||
_match = _match.substring(1);
|
||||
}
|
||||
if (match.endsWith('*')) {
|
||||
_match = _match.substring(0, _match.length - 1);
|
||||
}
|
||||
_match = utils.escapeRegexChars(_match);
|
||||
if (!match.startsWith('*')) {
|
||||
_match = '^' + _match;
|
||||
}
|
||||
if (!match.endsWith('*')) {
|
||||
_match += '$';
|
||||
}
|
||||
return _match;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (module) {
|
||||
const helpers = require('./helpers');
|
||||
module.flushdb = async function () {
|
||||
await module.client.dropDatabase();
|
||||
};
|
||||
@@ -27,6 +28,13 @@ module.exports = function (module) {
|
||||
return item !== undefined && item !== null;
|
||||
};
|
||||
|
||||
module.scan = async function (params) {
|
||||
const match = helpers.buildMatchQuery(params.match);
|
||||
return await module.client.collection('objects').distinct(
|
||||
'_key', { _key: { $regex: new RegExp(match) } }
|
||||
);
|
||||
};
|
||||
|
||||
module.delete = async function (key) {
|
||||
if (!key) {
|
||||
return;
|
||||
|
||||
@@ -472,20 +472,7 @@ module.exports = function (module) {
|
||||
project.score = 1;
|
||||
}
|
||||
|
||||
let match = params.match;
|
||||
if (params.match.startsWith('*')) {
|
||||
match = match.substring(1);
|
||||
}
|
||||
if (params.match.endsWith('*')) {
|
||||
match = match.substring(0, match.length - 1);
|
||||
}
|
||||
match = utils.escapeRegexChars(match);
|
||||
if (!params.match.startsWith('*')) {
|
||||
match = '^' + match;
|
||||
}
|
||||
if (!params.match.endsWith('*')) {
|
||||
match += '$';
|
||||
}
|
||||
const match = helpers.buildMatchQuery(params.match);
|
||||
let regex;
|
||||
try {
|
||||
regex = new RegExp(match);
|
||||
|
||||
Reference in New Issue
Block a user