Skip to content

Commit 4463468

Browse files
authored
Create pattern blob for indexing (#2060)
* 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 #2048
1 parent 91e7903 commit 4463468

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

controllers/scriptStorage.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,6 +2062,8 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
20622062
var now = null;
20632063

20642064
var storeDescriptionLength = null;
2065+
var includes = null;
2066+
var matches = null;
20652067

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

2090+
includes = findMeta(aMeta, 'UserScript.include.value');
2091+
matches = findMeta(aMeta, 'UserScript.match.value');
20882092

20892093
storeDescriptionLength = settings.scriptSearchQueryStoreMaxDescription;
20902094
storeDescriptionLength = rLogographic.test(thisDescription)
@@ -2111,6 +2115,8 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
21112115
installName: installName,
21122116
fork: null,
21132117
meta: aMeta,
2118+
_pattern: ((includes ? includes.join(' ') : '') + ' '
2119+
+ (matches ? matches.join(' ') : '')).trim(),
21142120
isLib: isLib,
21152121
uses: isLib ? null : libraries,
21162122
_authorId: aUser._id
@@ -2147,6 +2153,13 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
21472153
: ''
21482154
);
21492155
aScript.meta = aMeta;
2156+
2157+
includes = findMeta(aMeta, 'UserScript.include.value');
2158+
matches = findMeta(aMeta, 'UserScript.match.value');
2159+
2160+
aScript._pattern = ((includes ? includes.join(' ') : '') + ' '
2161+
+ (matches ? matches.join(' ') : '')).trim()
2162+
21502163
aScript.uses = libraries;
21512164

21522165
// Okay to update

libs/modelQuery.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ var parseScriptSearchQuery = function (aScriptListQuery, aQuery, aLimited) {
125125
});
126126
} else {
127127
parseModelListSearchQuery(aScriptListQuery, aQuery, {
128-
partialWordMatchFields: ['name', '_description', 'author', '_about' ],
129-
fullWordMatchFields: ['meta.UserScript.include.value', 'meta.UserScript.match.value']
128+
partialWordMatchFields: ['name', 'author', '_description', '_about'],
129+
fullWordMatchFields: ['_pattern']
130130
});
131131
}
132132
};

models/script.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var scriptSchema = new Schema({
1515
// Visible
1616
name: String,
1717
_description: String,
18+
_pattern: String,
1819
author: String,
1920
installs: { type: Number, default: 0 },
2021
installsSinceUpdate: { type: Number, default: 0 },
@@ -54,6 +55,7 @@ scriptSchema.index({
5455
isLib: 1,
5556
name: 1,
5657
author: 1,
58+
_pattern: 1,
5759
_description: 1,
5860
_about: 1
5961
});

0 commit comments

Comments
 (0)