Skip to content

Commit

Permalink
More limits (Plan B) (#1629)
Browse files Browse the repository at this point in the history
* Limit a few more things to possibly curtail some 431's
* Ease up on MongoDB having issues with script querying and CPU load. Limit to first copied block of characters in `about`. This amount may get smaller and is currently in flux.
* Create new clipped searchable fields. I spent a lot of time to see if MongoDB/*mongoose* had a limiter on their indexer and couldn't find one so we get to do it manually.

NOTE:
* This will temporarily remove everyone's Summary but it will be manually migrated in the DB in a while. If you are impatient... edit your script *(no changes necessary)* and resave it... that will do the migration also.

Post #1628 and applies to #1548

Auto-merge
  • Loading branch information
Martii committed Jun 28, 2019
1 parent 2df9157 commit 1923b57
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 6 deletions.
5 changes: 3 additions & 2 deletions controllers/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ exports.view = function (aReq, aRes, aNext) {
function preRender() {
if (script.groups) {
pageMetadata(options, ['About', script.name, (script.isLib ? 'Libraries' : 'Userscripts')],
script.description, _.pluck(script.groups, 'name'));
script._description, _.pluck(script.groups, 'name'));
}
}

Expand Down Expand Up @@ -382,7 +382,7 @@ exports.view = function (aReq, aRes, aNext) {

// Page metadata
pageMetadata(options, ['About', script.name, (script.isLib ? 'Libraries' : 'Userscripts')],
script.description);
script._description);
options.isScriptPage = true;

// SearchBar
Expand Down Expand Up @@ -469,6 +469,7 @@ exports.edit = function (aReq, aRes, aNext) {
} else if (typeof aReq.body.about !== 'undefined') {
// POST
aScript.about = aReq.body.about;
aScript._about = (aScript.about ? aScript.about.substr(0, 512) : null);
scriptGroups = (aReq.body.groups || '');
scriptGroups = scriptGroups.split(/,/);
addScriptToGroups(aScript, scriptGroups, function () {
Expand Down
33 changes: 32 additions & 1 deletion controllers/scriptStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,9 @@ function isEqualKeyset(aSlaveKeyset, aMasterKeyset) {
exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
var isLib = !!findMeta(aMeta, 'UserLibrary');
var scriptName = null;
var scriptDescription = null;
var thisName = null;
var thisDescription = null;

async.series([
function (aInnerCallback) {
Expand Down Expand Up @@ -1224,6 +1226,14 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
return;
}

if (scriptName.length > 128) {
aInnerCallback(new statusError({
message: '`@name` too long.',
code: 400
}), null);
return;
}

// Can't install a script name ending in a reserved extension
if (/\.(?:min|user|user\.js|meta)$/.test(scriptName)) {
aInnerCallback(new statusError({
Expand All @@ -1249,10 +1259,28 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
aInnerCallback(null);
},
function (aInnerCallback) {
// `@description` validations including localizations
// `@description` validations
var description = null;
var masterKeyset = null;
var slaveKeyset = null;

if (!isLib) {
description = findMeta(aMeta, 'UserScript.description');
} else {
description = findMeta(aMeta, 'UserLibrary.description');
}

// Check for non-localized presence
if (description) {
description.forEach(function (aElement, aIndex, aArray) {
if (!description[aIndex].key) {
thisDescription = aElement.value;
scriptDescription = cleanFilename(thisDescription, '');
}
});
}

// `@description` validations including localizations
masterKeyset = findMeta(aMeta, 'UserScript.description.value');
slaveKeyset = findMeta(aMeta, 'UserLibrary.description.value');

Expand Down Expand Up @@ -1768,10 +1796,12 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
// New script
aScript = new Script({
name: thisName,
_description: (thisDescription ? thisDescription.substr(0, 512) : null),
author: aUser.name,
installs: 0,
rating: 0,
about: '',
_about: '',
updated: new Date(),
hash: crypto.createHash('sha512').update(aBuf).digest('hex'),
votes: 0,
Expand Down Expand Up @@ -1803,6 +1833,7 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
}), null);
return;
}
aScript._description = (thisDescription ? thisDescription.substr(0, 512) : null);
aScript.meta = aMeta;
aScript.uses = libraries;

Expand Down
4 changes: 4 additions & 0 deletions libs/modelParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ var parseScript = function (aScript) {
script.description = aElement.value;
}
});

if (script.description && script._description && script.description.length > script._description.length) {
script.hasLongDescription = true;
}
}

// Icons
Expand Down
2 changes: 1 addition & 1 deletion libs/modelQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ var parseModelListSearchQuery = function (aModelListQuery, aQuery, aSearchOption

var parseScriptSearchQuery = function (aScriptListQuery, aQuery) {
parseModelListSearchQuery(aScriptListQuery, aQuery, {
partialWordMatchFields: ['name', 'author', 'about', 'meta.UserScript.description.value'],
partialWordMatchFields: ['name', '_description', 'author', '_about' ],
fullWordMatchFields: ['meta.UserScript.include.value', 'meta.UserScript.match.value']
});
};
Expand Down
2 changes: 2 additions & 0 deletions models/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ var Schema = mongoose.Schema;
var scriptSchema = new Schema({
// Visible
name: String,
_description: String,
author: String,
installs: { type: Number, default: 0 },
installsSinceUpdate: { type: Number, default: 0 },
rating: Number,
about: String,
_about: String,
updated: Date,
hash: String,

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "OpenUserJS.org",
"description": "An open source user scripts repo built using Node.js",
"version": "0.3.0",
"version": "0.4.0",
"main": "app",
"dependencies": {
"ace-builds": "git://github.com/ajaxorg/ace-builds.git#7489e42",
Expand Down
2 changes: 1 addition & 1 deletion views/includes/scriptList.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<span class="script-version label label-default">{{value}}</span>
{{/meta.UserScript.version}}
<span class="inline-block">by <a href="{{{author.userPageUrl}}}">{{author.name}}</a></span>
{{#description}}<p>{{description}}</p>{{/description}}
{{#_description}}<p>{{_description}}{{#hasLongDescription}}<strong>&hellip;</strong>{{/hasLongDescription}}</p>{{/_description}}
</td>
{{^librariesOnly}}
<td class="text-center td-fit">
Expand Down

0 comments on commit 1923b57

Please sign in to comment.