From 563f57d61775dead6d46bbc821ce60d9654f2dd8 Mon Sep 17 00:00:00 2001 From: raclim Date: Wed, 7 Aug 2024 14:52:48 -0400 Subject: [PATCH 1/5] add lean to mongodb user queries --- server/controllers/user.controller.js | 4 +++- server/models/user.js | 2 ++ server/views/404Page.js | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/server/controllers/user.controller.js b/server/controllers/user.controller.js index da5f4c615c..b3d6894a1b 100644 --- a/server/controllers/user.controller.js +++ b/server/controllers/user.controller.js @@ -171,7 +171,9 @@ export async function validateResetPasswordToken(req, res) { const user = await User.findOne({ resetPasswordToken: req.params.token, resetPasswordExpires: { $gt: Date.now() } - }).exec(); + }) + .lean() + .exec(); if (!user) { res.status(401).json({ success: false, diff --git a/server/models/user.js b/server/models/user.js index d1c5e16bf2..e1a2b843e1 100644 --- a/server/models/user.js +++ b/server/models/user.js @@ -310,6 +310,7 @@ userSchema.statics.findByEmailOrUsername = async function findByEmailOrUsername( const foundUser = await user .findOne(query) .collation({ locale: 'en', strength: 2 }) + .lean() .exec(); return foundUser; @@ -343,6 +344,7 @@ userSchema.statics.findByEmailAndUsername = async function findByEmailAndUsernam const foundUser = await user .findOne(query) .collation({ locale: 'en', strength: 2 }) + .lean() .exec(); return foundUser; diff --git a/server/views/404Page.js b/server/views/404Page.js index 7c864f4009..72b7de54f8 100644 --- a/server/views/404Page.js +++ b/server/views/404Page.js @@ -78,13 +78,13 @@ export const get404Sketch = async () => { `); try { - const p5User = await User.findOne({ username: 'p5' }).exec(); + const p5User = await User.findOne({ username: 'p5' }).lean().exec(); if (!p5User) { return errorMessage; } - const projects = await Project.find({ user: p5User._id }).exec(); + const projects = await Project.find({ user: p5User._id }).lean().exec(); if (!projects.length) { return errorMessage; From 2a9b22f47ffe6b8e86457a8508fc674e1e6641f0 Mon Sep 17 00:00:00 2001 From: raclim Date: Wed, 7 Aug 2024 14:53:29 -0400 Subject: [PATCH 2/5] index user for project schema --- server/models/project.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/models/project.js b/server/models/project.js index a909591f1f..492782541f 100644 --- a/server/models/project.js +++ b/server/models/project.js @@ -76,5 +76,7 @@ projectSchema.methods.isSlugUnique = async function isSlugUnique() { }; }; +projectSchema.index({ user: 1 }, { collation: { locale: 'en', strength: 2 } }); + export default mongoose.models.Project || mongoose.model('Project', projectSchema); From d8d6d82e16268b27be7ef56844ed6f4c18e829ad Mon Sep 17 00:00:00 2001 From: raclim Date: Wed, 7 Aug 2024 15:41:54 -0400 Subject: [PATCH 3/5] 2.14.2 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 59d7d7ca22..7739768a34 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "p5.js-web-editor", - "version": "2.14.1", + "version": "2.14.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "p5.js-web-editor", - "version": "2.14.1", + "version": "2.14.2", "license": "LGPL-2.1", "dependencies": { "@auth0/s3": "^1.0.0", diff --git a/package.json b/package.json index a54a305579..36155e2c1f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "p5.js-web-editor", - "version": "2.14.1", + "version": "2.14.2", "description": "The web editor for p5.js.", "scripts": { "clean": "rimraf dist", From 622ddfe794c31fc88fe1a842f57382fd45aa8835 Mon Sep 17 00:00:00 2001 From: raclim <43053081+raclim@users.noreply.github.com> Date: Wed, 7 Aug 2024 16:27:46 -0400 Subject: [PATCH 4/5] Revert "Improve performance for user database queries" --- server/controllers/user.controller.js | 4 +--- server/models/project.js | 2 -- server/models/user.js | 2 -- server/views/404Page.js | 4 ++-- 4 files changed, 3 insertions(+), 9 deletions(-) diff --git a/server/controllers/user.controller.js b/server/controllers/user.controller.js index b3d6894a1b..da5f4c615c 100644 --- a/server/controllers/user.controller.js +++ b/server/controllers/user.controller.js @@ -171,9 +171,7 @@ export async function validateResetPasswordToken(req, res) { const user = await User.findOne({ resetPasswordToken: req.params.token, resetPasswordExpires: { $gt: Date.now() } - }) - .lean() - .exec(); + }).exec(); if (!user) { res.status(401).json({ success: false, diff --git a/server/models/project.js b/server/models/project.js index 492782541f..a909591f1f 100644 --- a/server/models/project.js +++ b/server/models/project.js @@ -76,7 +76,5 @@ projectSchema.methods.isSlugUnique = async function isSlugUnique() { }; }; -projectSchema.index({ user: 1 }, { collation: { locale: 'en', strength: 2 } }); - export default mongoose.models.Project || mongoose.model('Project', projectSchema); diff --git a/server/models/user.js b/server/models/user.js index e1a2b843e1..d1c5e16bf2 100644 --- a/server/models/user.js +++ b/server/models/user.js @@ -310,7 +310,6 @@ userSchema.statics.findByEmailOrUsername = async function findByEmailOrUsername( const foundUser = await user .findOne(query) .collation({ locale: 'en', strength: 2 }) - .lean() .exec(); return foundUser; @@ -344,7 +343,6 @@ userSchema.statics.findByEmailAndUsername = async function findByEmailAndUsernam const foundUser = await user .findOne(query) .collation({ locale: 'en', strength: 2 }) - .lean() .exec(); return foundUser; diff --git a/server/views/404Page.js b/server/views/404Page.js index 72b7de54f8..7c864f4009 100644 --- a/server/views/404Page.js +++ b/server/views/404Page.js @@ -78,13 +78,13 @@ export const get404Sketch = async () => { `); try { - const p5User = await User.findOne({ username: 'p5' }).lean().exec(); + const p5User = await User.findOne({ username: 'p5' }).exec(); if (!p5User) { return errorMessage; } - const projects = await Project.find({ user: p5User._id }).lean().exec(); + const projects = await Project.find({ user: p5User._id }).exec(); if (!projects.length) { return errorMessage; From 2a1da67cd93756e2b62ff6682dec2deee8b5c212 Mon Sep 17 00:00:00 2001 From: raclim Date: Wed, 7 Aug 2024 16:35:04 -0400 Subject: [PATCH 5/5] 2.14.3 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7739768a34..c25bac00b4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "p5.js-web-editor", - "version": "2.14.2", + "version": "2.14.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "p5.js-web-editor", - "version": "2.14.2", + "version": "2.14.3", "license": "LGPL-2.1", "dependencies": { "@auth0/s3": "^1.0.0", diff --git a/package.json b/package.json index 36155e2c1f..f912b882dd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "p5.js-web-editor", - "version": "2.14.2", + "version": "2.14.3", "description": "The web editor for p5.js.", "scripts": { "clean": "rimraf dist",