Skip to content

Commit

Permalink
Create pattern blob for indexing
Browse files Browse the repository at this point in the history
* We'll see if this improves things on pro. Dev is not useful as all queries finish in under 2000ms usually due to higher CPU/MEM configuration.
* Rearrange indexing to closely match query order

Post OpenUserJS#2048
  • Loading branch information
Martii committed Mar 4, 2025
1 parent 91e7903 commit 9d776f9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
13 changes: 13 additions & 0 deletions controllers/scriptStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2062,6 +2062,8 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
var now = null;

var storeDescriptionLength = null;
var includes = null;
var matches = null;

if (aRemoved) {
aCallback(new statusError({
Expand All @@ -2085,6 +2087,8 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
// New script
now = new Date();

includes = findMeta(aMeta, 'UserScript.include.value');
matches = findMeta(aMeta, 'UserScript.match.value');

storeDescriptionLength = settings.scriptSearchQueryStoreMaxDescription;
storeDescriptionLength = rLogographic.test(thisDescription)
Expand All @@ -2111,6 +2115,8 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
installName: installName,
fork: null,
meta: aMeta,
_pattern: ((includes ? includes.join(' ') : '') + ' '
+ (matches ? matches.join(' ') : '')).trim(),
isLib: isLib,
uses: isLib ? null : libraries,
_authorId: aUser._id
Expand Down Expand Up @@ -2147,6 +2153,13 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
: ''
);
aScript.meta = aMeta;

includes = findMeta(aMeta, 'UserScript.include.value');
matches = findMeta(aMeta, 'UserScript.match.value');

aScript._pattern = ((includes ? includes.join(' ') : '') + ' '
+ (matches ? matches.join(' ') : '')).trim()

aScript.uses = libraries;

// Okay to update
Expand Down
4 changes: 2 additions & 2 deletions libs/modelQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ var parseScriptSearchQuery = function (aScriptListQuery, aQuery, aLimited) {
});
} else {
parseModelListSearchQuery(aScriptListQuery, aQuery, {
partialWordMatchFields: ['name', '_description', 'author', '_about' ],
fullWordMatchFields: ['meta.UserScript.include.value', 'meta.UserScript.match.value']
partialWordMatchFields: ['name', 'author', '_description', '_about'],
fullWordMatchFields: ['_pattern']
});
}
};
Expand Down
2 changes: 2 additions & 0 deletions models/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var scriptSchema = new Schema({
// Visible
name: String,
_description: String,
_pattern: String,
author: String,
installs: { type: Number, default: 0 },
installsSinceUpdate: { type: Number, default: 0 },
Expand Down Expand Up @@ -54,6 +55,7 @@ scriptSchema.index({
isLib: 1,
name: 1,
author: 1,
_pattern: 1,
_description: 1,
_about: 1
});
Expand Down

0 comments on commit 9d776f9

Please sign in to comment.