Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Bump mongoose 5.13.20 => 6.13.8 and fix compatibility. #715

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async.waterfall([
db = mongoose.createConnection() // http://mongoosejs.com/docs/api.html#connection_Connection
.once('open', openHandler)
.once('error', errFirstHandler);
db.open(moongoUri, { server: { poolSize: moongoPool, auto_reconnect: true }, db: { safe: true } });
db.open(moongoUri, { server: { maxPoolSize: moongoPool, auto_reconnect: true }, db: { safe: true } });

function openHandler() {
const admin = new mongoose.mongo.Admin(db.db);
Expand Down
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export async function configure(startStamp) {

await connectDb({
redis: config.redis,
mongo: { uri: config.mongo.connection, poolSize: config.mongo.pool },
mongo: { uri: config.mongo.connection, maxPoolSize: config.mongo.pool },
logger,
});

Expand Down
2 changes: 1 addition & 1 deletion config/default.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module.exports = {

mongo: {
connection: 'mongodb://localhost:27017/pastvu',
pool: 5, // Number of concurrent connections to DB
pool: 10, // Number of concurrent connections to DB
},
mongo_api: {
con: 'mongodb://localhost:27017/pastvu',
Expand Down
4 changes: 2 additions & 2 deletions controllers/_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ async function popUserRegions(usObj) {
paths.push({ path: 'mod_regions', select: { _id: 1, cid: 1, parents: 1, title_en: 1, title_local: 1 } });
}

await user.populate(paths).execPopulate();
await user.populate(paths);

let regionsData = regionController.buildQuery(user.regions);
let shortRegions = regionController.getShortRegionsParams(regionsData.rhash);
Expand Down Expand Up @@ -754,7 +754,7 @@ export const archiveExpiredSessions = async function () {
const anonQuery = { anonym: { $exists: true }, stamp: { $lte: new Date(start - SESSION_ANON_LIFE) } };

// Simply remove anonymous sessions older then SESSION_ANON_LIFE, there is no point in storing them
const { n: countRemovedAnon } = await Session.deleteMany(anonQuery).exec();
const { deletedCount: countRemovedAnon } = await Session.deleteMany(anonQuery).exec();

// Move each expired registered user session to sessions_archive
for await (const session of Session.find(userQuery).limit(5000)) {
Expand Down
2 changes: 1 addition & 1 deletion controllers/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ async function clusterRecalcByPhoto(g, zParam, geoPhotos, yearPhotos, isPainting
$update.$set.geo = geoCluster;
$update.$set.y = yCluster;

const { n: count = 0 } = await ClusterModel.updateOne({ g, z: zParam.z }, $update, { upsert: true }).exec();
const { matchedCount: count = 0 } = await ClusterModel.updateOne({ g, z: zParam.z }, $update, { upsert: true }).exec();

return count;
}
Expand Down
4 changes: 2 additions & 2 deletions controllers/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@ async function setNoComments({ cid, type = 'photo', val: nocomments }) {
}

export async function changeObjCommentsStatus({ obj: { _id: objId, s } }) {
const { n: count = 0 } = await Comment.updateMany({ obj: objId }, { $set: { s } }).exec();
const { matchedCount: count = 0 } = await Comment.updateMany({ obj: objId }, { $set: { s } }).exec();

return count;
}
Expand Down Expand Up @@ -1698,7 +1698,7 @@ export async function changeObjCommentsVisibility({ obj, hide }) {
export async function changePhotoCommentsType({ photo: { _id: objId, type } }) {
const command = { $set: { type } };

const { n: count = 0 } = await Comment.updateMany({ obj: objId }, command).exec();
const { matchedCount: count = 0 } = await Comment.updateMany({ obj: objId }, command).exec();

return { count };
}
Expand Down
14 changes: 5 additions & 9 deletions controllers/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,20 @@ function init({ mongo, redis, logger = log4js.getLogger('app') }) {

if (mongo) {
const mongoose = require('mongoose');
const { uri, poolSize = 1 } = mongo;
const { uri, maxPoolSize = 1 } = mongo;
let connErrorLogLevel = 'error';

// Set native Promise as mongoose promise provider
mongoose.Promise = Promise;
// For 5.x compatibility, defaults again to false in 7.x, but 'strict' in 6.x. Remove when migrating to 7.x
mongoose.set('strictQuery', false);

connectionPromises.push(new Promise((resolve, reject) => {
mongoose.connect(uri, {
poolSize,
promiseLibrary: Promise,
maxPoolSize,
noDelay: true,
keepAlive: 0, // Enable keep alive connection
socketTimeoutMS: 0,
connectTimeoutMS: ms('5m'),
useUnifiedTopology: true, // Use new topology engine (since MongoDB driver 3.3)
useNewUrlParser: true, // Use new connection string parser.
useCreateIndex: true, // Use createIndex internally (ensureIndex is deprecated in MongoDB driver 3.2).
useFindAndModify: false, // Use findOneAndUpdate interally (findAndModify is deprecated in MongoDB driver 3.1).
autoIndex: false, // Do not attempt to create index automatically, we use syncIndexes in worker.
}).then(openHandler, errFirstHandler);

Expand Down Expand Up @@ -109,7 +105,7 @@ function init({ mongo, redis, logger = log4js.getLogger('app') }) {
logger.info(
`MongoDB[${buildInfo.version}, ${serverStatus.storageEngine.name}, x${buildInfo.bits},`,
`pid ${serverStatus.pid}] connected through Mongoose[${mongoose.version}]`,
`with poolsize ${poolSize} at ${uri}`
`with poolsize ${maxPoolSize} at ${uri}`
);

// Hook on events.
Expand Down
4 changes: 2 additions & 2 deletions controllers/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ async function conveyerClear({ value }) {
if (value === true) {
conveyerEnabled = value;

({ n: removedCount = 0 } = await PhotoConveyer.deleteMany({ converting: { $exists: false } }).exec());
({ deletedCount: removedCount = 0 } = await PhotoConveyer.deleteMany({ converting: { $exists: false } }).exec());
}

conveyerLength = await PhotoConveyer.estimatedDocumentCount().exec();
Expand Down Expand Up @@ -785,7 +785,7 @@ export async function removePhotos(cids) {
return 0;
}

const { n: removedCount = 0 } = await PhotoConveyer.deleteMany({ cid: { $in: cids } }).exec();
const { deletedCount: removedCount = 0 } = await PhotoConveyer.deleteMany({ cid: { $in: cids } }).exec();

conveyerLength -= removedCount;

Expand Down
4 changes: 2 additions & 2 deletions controllers/photo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2790,7 +2790,7 @@ async function resetIndividualDownloadOrigin({ login, r }) {
query[`r${region.level}`] = region.cid;
}

const { n: updated = 0 } = await Photo.updateMany(
const { matchedCount: updated = 0 } = await Photo.updateMany(
query, { $unset: { disallowDownloadOriginIndividual: 1 } }
).exec();

Expand Down Expand Up @@ -3443,7 +3443,7 @@ const planResetDisplayStat = (function () {
try {
logger.info(`Resetting day ${needWeek ? 'and week ' : ''}display statistics...`);

const { n: count = 0 } = await Photo.updateMany(
const { matchedCount: count = 0 } = await Photo.updateMany(
{ s: { $in: [status.PUBLIC, status.DEACTIVATE, status.REMOVE] } }, { $set: setQuery }
).exec();

Expand Down
16 changes: 8 additions & 8 deletions controllers/region.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,14 +491,14 @@ async function calcRegionIncludes(cidOrRegion) {

// First clear assignment of objects with coordinates to region
const unsetObject = { $unset: { [level]: 1 } };
const [{ n: photosCountBefore = 0 }, { n: commentsCountBefore = 0 }] = await Promise.all([
const [{ matchedCount: photosCountBefore = 0 }, { matchedCount: commentsCountBefore = 0 }] = await Promise.all([
Photo.updateMany({ geo: { $exists: true }, [level]: region.cid }, unsetObject).exec(),
Comment.updateMany({ geo: { $exists: true }, [level]: region.cid }, unsetObject).exec(),
]);

// Then assign to region on located in it polygon objects
const setObject = { $set: { [level]: region.cid } };
const [{ n: photosCountAfter = 0 }, { n: commentsCountAfter = 0 }] = await Promise.all([
const [{ matchedCount: photosCountAfter = 0 }, { matchedCount: commentsCountAfter = 0 }] = await Promise.all([
Photo.updateMany({ geo: { $geoWithin: { $geometry: region.geo } } }, setObject).exec(),
Comment.updateMany({ geo: { $geoWithin: { $geometry: region.geo } } }, setObject).exec(),
]);
Expand Down Expand Up @@ -643,7 +643,7 @@ async function changeRegionParentExternality(region, oldParentsArray, childLenAr

movingRegionsIds.unshift(region._id);

const [{ n: affectedUsers = 0 }, { n: affectedMods = 0 }] = await Promise.all([
const [{ matchedCount: affectedUsers = 0 }, { matchedCount: affectedMods = 0 }] = await Promise.all([
// Remove subscription on moving regions of those users, who have subscription on new and on parent regions,
// because in this case they'll have subscription on children automatically
User.updateMany({
Expand Down Expand Up @@ -1265,12 +1265,12 @@ async function remove(data) {
removingRegionsIds.push(regionToRemove._id);

// Replace home regions
const { n: homeAffectedUsers = 0 } = await User.updateMany(
const { matchedCount: homeAffectedUsers = 0 } = await User.updateMany(
{ regionHome: { $in: removingRegionsIds } }, { $set: { regionHome: parentRegion._id } }
).exec();

// Unsubscribe all users from removing regions ('my regions')
const { n: affectedUsers = 0 } = await User.updateMany(
const { matchedCount: affectedUsers = 0 } = await User.updateMany(
{ regions: { $in: removingRegionsIds } }, { $pull: { regions: { $in: removingRegionsIds } } }
).exec();

Expand All @@ -1293,7 +1293,7 @@ async function remove(data) {
}
}

const [{ n: affectedPhotos = 0 }, { n: affectedComments = 0 }] = await Promise.all([
const [{ matchedCount: affectedPhotos = 0 }, { matchedCount: affectedComments = 0 }] = await Promise.all([
// Update included photos
Photo.updateMany(objectsMatchQuery, objectsUpdateQuery).exec(),
// Update comments of included photos
Expand Down Expand Up @@ -1343,13 +1343,13 @@ async function removeRegionsFromMods(usersQuery, regionsIds) {

if (modUsersCids.length) {
// Remove regions from finded moderators
const { n: affectedMods = 0 } = await User.updateMany(
const { matchedCount: affectedMods = 0 } = await User.updateMany(
{ cid: { $in: modUsersCids } },
{ $pull: { mod_regions: { $in: regionsIds } } }
).exec();

// Revoke moderation role from users, in whose no moderation regions left after regions removal
const { n: affectedModsLose = 0 } = await User.updateMany(
const { matchedCount: affectedModsLose = 0 } = await User.updateMany(
{ cid: { $in: modUsersCids }, mod_regions: { $size: 0 } },
{ $unset: { role: 1, mod_regions: 1 } }
).exec();
Expand Down
2 changes: 1 addition & 1 deletion controllers/subscr.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export async function commentAdded(objId, user, stamp = new Date()) {
*/
export async function commentViewed(objId, user, setInRel) {
if (setInRel) {
const { n: numberAffected = 0 } = await UserObjectRel.updateOne(
const { matchedCount: numberAffected = 0 } = await UserObjectRel.updateOne(
{ obj: objId, user: user._id },
{ $unset: { sbscr_noty: 1 }, $set: { sbscr_noty_change: new Date() } },
{ upsert: false }
Expand Down
2 changes: 1 addition & 1 deletion controllers/userobjectrel.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export async function setCommentView(objId, userId, type = 'photo', stamp = new
* @param {string} [type=photo] Object type
*/
export async function onCommentAdd(objId, userId, type = 'photo') {
const { n: count = 0 } = await UserObjectRel.updateMany(
const { matchedCount: count = 0 } = await UserObjectRel.updateMany(
{ obj: objId, comments: { $exists: true }, user: { $ne: userId }, type },
{ $inc: { ccount_new: 1 } }
).exec();
Expand Down
2 changes: 1 addition & 1 deletion downloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export async function configure(startStamp) {

await connectDb({
redis: config.redis,
mongo: { uri: config.mongo.connection, poolSize: config.mongo.pool },
mongo: { uri: config.mongo.connection, maxPoolSize: config.mongo.pool },
logger,
});

Expand Down
2 changes: 1 addition & 1 deletion notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function configure(startStamp) {

await connectDb({
redis: config.redis,
mongo: { uri: config.mongo.connection, poolSize: config.mongo.pool },
mongo: { uri: config.mongo.connection, maxPoolSize: config.mongo.pool },
logger,
});

Expand Down
Loading