Skip to content

Commit bec94da

Browse files
authored
fix(deps): Updates Mongo to 4.2 (LLC-234) (#1541)
BREAKING CHANGE: Removes maxScan parameter from API BREAKING CHANGE: Requires Mongo 4.2
1 parent c3283fe commit bec94da

File tree

12 files changed

+16
-42
lines changed

12 files changed

+16
-42
lines changed

Diff for: .circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jobs:
44
build:
55
docker:
66
- image: circleci/node:10
7-
- image: mongo:3.4-jessie
7+
- image: mongo:4.2-bionic
88
- image: redis:4-alpine
99
environment:
1010
TERM: xterm

Diff for: .env.example

-4
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ REDIS_PREFIX=LEARNINGLOCKER
8787
# https://docs.mongodb.com/manual/reference/operator/meta/maxTimeMS/
8888
#MAX_TIME_MS=
8989

90-
# Maximum number of documents an aggregation can scan
91-
# https://docs.mongodb.com/manual/reference/operator/meta/maxScan/
92-
#MAX_SCAN=
93-
9490
# Turn off fuzzy scoring on persona matching
9591
# Set to true to make persona workers much faster at scale (default is true)
9692
#DISABLE_PERSONA_SCORING=true

Diff for: api/src/controllers/PersonaController.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import getJSONFromQuery from 'api/utils/getJSONFromQuery';
44
import getFromQuery from 'api/utils/getFromQuery';
55
import getOrgFromAuthInfo from 'lib/services/auth/authInfoSelectors/getOrgFromAuthInfo';
66
import getScopeFilter from 'lib/services/auth/filters/getScopeFilter';
7-
import { MAX_TIME_MS, MAX_SCAN } from 'lib/models/plugins/addCRUDFunctions';
7+
import { MAX_TIME_MS } from 'lib/models/plugins/addCRUDFunctions';
88
import parseQuery from 'lib/helpers/parseQuery';
99
import { CursorDirection } from '@learninglocker/persona-service/dist/service/constants';
1010
import { entityResponse, entitiesResponse } from 'api/controllers/utils/entitiesResponse';
@@ -47,8 +47,7 @@ const personaConnection = catchErrors(async (req, res) => {
4747
filter,
4848
project,
4949
hint,
50-
maxTimeMS: MAX_TIME_MS,
51-
maxScan: MAX_SCAN
50+
maxTimeMS: MAX_TIME_MS
5251
};
5352

5453
const result = await personaService.getPersonasConnection(params);

Diff for: api/src/controllers/PersonaIdentifierController.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import getAuthFromRequest from 'lib/helpers/getAuthFromRequest';
99
import getScopeFilter from 'lib/services/auth/filters/getScopeFilter';
1010
import { CursorDirection } from '@learninglocker/persona-service/dist/service/constants';
1111
import Locked from '@learninglocker/persona-service/dist/errors/Locked';
12-
import { MAX_TIME_MS, MAX_SCAN } from 'lib/models/plugins/addCRUDFunctions';
12+
import { MAX_TIME_MS } from 'lib/models/plugins/addCRUDFunctions';
1313
import parseQuery from 'lib/helpers/parseQuery';
1414
import asignIdentifierToStatements from 'lib/services/persona/asignIdentifierToStatements';
1515
import identifierHasStatements from 'lib/services/persona/identifierHasStatements';
@@ -67,8 +67,7 @@ const personaIdentifierConnection = catchErrors(async (req, res) => {
6767
filter: filterNoUndefined,
6868
project,
6969
hint,
70-
maxTimeMS: MAX_TIME_MS,
71-
maxScan: MAX_SCAN
70+
maxTimeMS: MAX_TIME_MS
7271
});
7372

7473
return res.status(200).send(result);

Diff for: api/src/controllers/StatementController.js

-5
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ import catchErrors from 'api/controllers/utils/catchErrors';
66
import defaultTo from 'lodash/defaultTo';
77

88
const MAX_TIME_MS = defaultTo(Number(process.env.MAX_TIME_MS), 0);
9-
const MAX_SCAN = defaultTo(Number(process.env.MAX_SCAN), 0);
109

1110
const aggregate = (req) => {
1211
const authInfo = req.user.authInfo || {};
1312
const limit = Number(req.query.limit) || -1;
1413
const skip = Number(req.query.skip) || 0;
1514
const cache = (!!req.query.cache && req.query.cache !== 'false') || false;
1615
const maxTimeMS = Number(req.query.maxTimeMS) || MAX_TIME_MS;
17-
const maxScan = Number(req.query.maxScan) || MAX_SCAN;
1816
const pipeline = JSON.parse(req.query.pipeline);
1917
const sampleSize = Number(req.query.sampleSize) || undefined;
2018
const out = statementsService.aggregate({
@@ -23,7 +21,6 @@ const aggregate = (req) => {
2321
skip,
2422
cache,
2523
maxTimeMS,
26-
maxScan,
2724
pipeline,
2825
sampleSize
2926
});
@@ -87,15 +84,13 @@ const countStatements = catchErrors(async (req, res) => {
8784
getJSONFromQuery(req, 'query', {})
8885
);
8986
const maxTimeMS = getFromQuery(req, 'maxTimeMS', MAX_TIME_MS, Number);
90-
const maxScan = getFromQuery(req, 'maxScan', MAX_SCAN, Number);
9187
const hint = getJSONFromQuery(req, 'hint', null);
9288
const authInfo = getAuthFromRequest(req);
9389

9490
const count = await statementsService.countStatements({
9591
authInfo,
9692
filter,
9793
maxTimeMS,
98-
maxScan,
9994
hint
10095
});
10196

Diff for: api/src/utils/exports.js

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ export const exportCSV = ({ authInfo, pipelines }) => new Promise((resolve, reje
4949
limit: 500000,
5050
getStream: true,
5151
maxTimeMS: 0,
52-
maxScan: 0,
5352
}, next),
5453
(err, streams) => {
5554
if (err) reject(err);

Diff for: cli/src/commands/v2-migrations/20171122100800_common_indexes.js

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ const createStatementIndexes = (connection) => {
3232
createIndexWithVoid('timestamp__id', { timestamp: -1, _id: -1 });
3333
createIndexWithVoid('stored__id', { stored: -1, _id: -1 });
3434
createIndex(stmts, 'statementId_lrs_id', { 'statement.id': 1, lrs_id: 1 });
35-
createIndexWithOrg('timestamp__id', { timestamp: -1, _id: 1 });
3635
createIndexWithOrg('stored__id', { stored: -1, _id: 1 });
3736
createIndexWithOrg('objId', objectIdIndex);
3837
createIndexWithOrg('verbId_objId', { ...verbIdIndex, ...objectIdIndex });

Diff for: lib/helpers/convert$personaIdent.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import _, { map, without } from 'lodash';
22
import getService from 'lib/connections/personaService';
33
import logger from 'lib/logger';
4-
import { MAX_TIME_MS, MAX_SCAN } from 'lib/models/plugins/addCRUDFunctions';
4+
import { MAX_TIME_MS } from 'lib/models/plugins/addCRUDFunctions';
55
import getOrgFromAuthInfo from 'lib/services/auth/authInfoSelectors/getOrgFromAuthInfo';
66

77
/**
@@ -30,8 +30,7 @@ const convertOpValue = async (identifier, {
3030
filter,
3131
organisation,
3232
limit: Number.MAX_SAFE_INTEGER,
33-
maxTimeMS: MAX_TIME_MS,
34-
maxScan: MAX_SCAN
33+
maxTimeMS: MAX_TIME_MS
3534
});
3635
attributes = map(result.edges, ({ node }) => node);
3736
} catch (err) {

Diff for: lib/models/plugins/addCRUDFunctions.js

+5-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const FORWARDS = 'forwards';
1313
export const MAX_TIME_MS = process.env.MAX_TIME_MS
1414
? Number(process.env.MAX_TIME_MS)
1515
: 0;
16-
export const MAX_SCAN = process.env.MAX_SCAN ? Number(process.env.MAX_SCAN) : 0;
1716

1817
const sortDirectionToOperator = (direction, paginationDirection) => {
1918
if (paginationDirection === FORWARDS) {
@@ -71,9 +70,9 @@ const modelToCursor = (model, sort) => {
7170
return cursor;
7271
};
7372

74-
const getLrsStatementCount = ({ orgFilter, maxTimeMS, maxScan, hint }) => {
73+
const getLrsStatementCount = ({ orgFilter, maxTimeMS, hint }) => {
7574
const LRS = getDBConnection().model('Lrs');
76-
const query = LRS.collection.find(orgFilter, {}, { maxTimeMS, maxScan });
75+
const query = LRS.collection.find(orgFilter, {}, { maxTimeMS });
7776
if (hint) query.hint(hint);
7877
return query
7978
.project({ statementCount: 1 })
@@ -149,8 +148,7 @@ async function getConnection({
149148
authInfo,
150149
hint,
151150
project,
152-
maxTimeMS = MAX_TIME_MS,
153-
maxScan = MAX_SCAN
151+
maxTimeMS = MAX_TIME_MS
154152
}) {
155153
const modelName = this.modelName;
156154
const actionName = 'view';
@@ -162,7 +160,7 @@ async function getConnection({
162160
actionName,
163161
});
164162

165-
const query = this.find(parsedScopeFilter, {}, { maxTimeMS, maxScan });
163+
const query = this.find(parsedScopeFilter, {}, { maxTimeMS });
166164

167165
// apply sort
168166
query.sort(sort);
@@ -265,7 +263,6 @@ async function getCount({
265263
filter,
266264
authInfo,
267265
maxTimeMS = MAX_TIME_MS,
268-
maxScan = MAX_SCAN,
269266
hint
270267
}) {
271268
const parsedScopeFilter = await getParsedScopedFilter({
@@ -283,11 +280,10 @@ async function getCount({
283280
return getLrsStatementCount({
284281
orgFilter: parsedScopeFilter,
285282
maxTimeMS,
286-
maxScan,
287283
hint
288284
});
289285
}
290-
const query = this.find(parsedScopeFilter, {}, { maxTimeMS, maxScan });
286+
const query = this.find(parsedScopeFilter, {}, { maxTimeMS });
291287
if (hint) query.hint(hint);
292288
return query.select({ _id: 0, organisation: 1 }).countDocuments();
293289
}

Diff for: lib/models/statement.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const ASYNC_AGGREGATION_CACHE_SECONDS = defaultTo(Number(process.env.ASYNC_AGGRE
3333
const ASYNC_AGGREGATION_TIMEOUT_MS = defaultTo(Number(process.env.ASYNC_AGGREGATION_TIMEOUT_MS), 0);
3434
const ASYNC_AGGREGATION_REFRESH_AFTER_SECONDS = defaultTo(Number(process.env.ASYNC_AGGREGATION_REFRESH_AFTER_SECONDS), 60); // 1 minute
3535
const MAX_TIME_MS = defaultTo(Number(process.env.MAX_TIME_MS), 0);
36-
const MAX_SCAN = defaultTo(Number(process.env.MAX_SCAN), 0);
3736

3837
let Statement;
3938
const schema = new mongoose.Schema({
@@ -107,11 +106,10 @@ schema.post('remove', async (statement, next) => {
107106
* limit
108107
* batchSize
109108
* maxTimeMS
110-
* maxScan
111109
* }
112110
* @return {Promise}
113111
*/
114-
const streamAggregation = ({ pipeline, skip, limit, batchSize, maxTimeMS, maxScan }) => {
112+
const streamAggregation = ({ pipeline, skip, limit, batchSize, maxTimeMS }) => {
115113
let query = Statement
116114
.aggregate(pipeline)
117115
.read('secondaryPreferred')
@@ -122,7 +120,6 @@ const streamAggregation = ({ pipeline, skip, limit, batchSize, maxTimeMS, maxSca
122120
query.options = {};
123121
}
124122
query.options.maxTimeMS = maxTimeMS;
125-
query.options.maxScan = maxScan;
126123

127124
return Promise.resolve(query
128125
.cursor({ batchSize })
@@ -187,7 +184,6 @@ schema.statics.aggregateByAuth = function aggregateByAuth(
187184
batchSize = 100,
188185
getStream = false,
189186
maxTimeMS = MAX_TIME_MS,
190-
maxScan = MAX_SCAN,
191187
sampleSize = undefined
192188
},
193189
cb = () => { }
@@ -220,13 +216,12 @@ schema.statics.aggregateByAuth = function aggregateByAuth(
220216
limit,
221217
batchSize,
222218
maxTimeMS,
223-
maxScan,
224219
}).then(stream => cb(null, stream));
225220
}
226221

227222
if (cache === false) {
228223
return streamAggregation({
229-
pipeline: finalPipeline, skip, limit, batchSize, maxTimeMS, maxScan
224+
pipeline: finalPipeline, skip, limit, batchSize, maxTimeMS
230225
}).then(stream =>
231226
streamToStringResult(stream)
232227
).then((result) => {
@@ -322,7 +317,6 @@ export const runAggregationAsync = async (
322317
limit,
323318
batchSize: 100,
324319
maxTimeMS: ASYNC_AGGREGATION_TIMEOUT_MS,
325-
maxScan: MAX_SCAN,
326320
}).then(streamToStringResult);
327321

328322
const startedAt = await redisClient.get(`${prefix}-STARTED-AT`);

Diff for: lib/services/statements/aggregate.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,12 @@ export default async ({
6262
skip,
6363
cache,
6464
maxTimeMS,
65-
maxScan,
6665
pipeline,
6766
sampleSize
6867
}) => {
6968
const pipelineWithDashboard = await dashboardPipeline({ authInfo, pipeline });
7069

71-
const options = { skip, limit, cache, batchSize: 100, maxTimeMS, maxScan, sampleSize };
70+
const options = { skip, limit, cache, batchSize: 100, maxTimeMS, sampleSize };
7271
const organisationId = await checkDashboardAuth(authInfo, pipelineWithDashboard);
7372
const authInfoWithOrgId = setOrgIdOnAuthInfo(authInfo, organisationId);
7473

Diff for: lib/services/statements/countStatements.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import Statement from 'lib/models/statement';
22
import parseQuery from 'lib/helpers/parseQuery';
33

4-
export default async ({ filter, authInfo, maxTimeMS, maxScan, hint }) => {
4+
export default async ({ filter, authInfo, maxTimeMS, hint }) => {
55
const parsedFilter = await parseQuery(filter, { authInfo });
66
return Statement.getCount({
77
filter: parsedFilter,
88
authInfo,
99
maxTimeMS,
10-
maxScan,
1110
hint
1211
});
1312
};

0 commit comments

Comments
 (0)