-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
140 lines (129 loc) · 3.54 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import { MongoInternals } from 'meteor/mongo';
import { Minimongo } from 'meteor/minimongo';
let Analyze = {
initialize() {
return this;
},
go() {
let observeCursors = this.getObserveCursors(),
cursorAnalysis = {}
;
observeCursors.forEach(cursor => {
let result = this.analyzeCursor(cursor);
cursorAnalysis[JSON.stringify(cursor)] = result;
});
return cursorAnalysis;
},
getObserveCursors() {
return Object
.keys(MongoInternals.defaultRemoteCollectionDriver().mongo._observeMultiplexers)
.map(cursorString => JSON.parse(cursorString))
;
},
analyzeCursor(cursor) {
let oplogBlockers = {};
_.each(this.oplogBlockerTests, (blocker, id) => {
if (blocker.test(cursor)) {
oplogBlockers[id] = blocker.explain(cursor);
}
});
return { cursor, oplogBlockers };
},
oplogBlockerTests: {
ordered: {
test(cursor) {
return cursor.ordered;
},
explain(cursor) {
return `Used at least one ordered observe callback. Try to avoid using any of the following: addedAt, changedAt, movedTo, removedAt, addedBefore, movedBefore.`;
},
},
badSelector: {
test(cursor) {
try {
let matcher = new Minimongo.Matcher(cursor.selector);
return false;
}
catch(e) {
return true;
}
},
explain(cursor) {
return `Minimongo couldn't compile the selector. Remove any $ operators that aren't available in older versions of Mongo.`;
},
},
oplogDisabled: {
test(cursor) {
return cursor.options.disableOplog || cursor.options._disableOplog;
},
explain(cursor) {
return `The oplog driver was manually disabled. Don't set disableOplog or _disableOplog.`;
},
},
hasSkip: {
test(cursor) {
return cursor.options.skip;
},
explain(cursor) {
return `A non-zero skip was set. Remove the skip.`;
},
},
unsortedLimit: {
test(cursor) {
return cursor.options.limit && !cursor.options.sort;
},
explain(cursor) {
return `A limit was set without adding a sort. Add a sort or remove the limit.`;
},
},
badProjection: {
test(cursor) {
if (!cursor.options.fields) {
return false;
}
try {
LocalCollection._checkSupportedProjection(cursor.options.fields);
}
catch (e) {
return true;
}
},
explain(cursor) {
return `The field projection configuration couldn't be compiled. Remove any $ operators from the fields option.`;
},
},
fancySelector: {
test(cursor) {
try {
let matcher = new Minimongo.Matcher(cursor.selector);
return matcher.hasWhere() || matcher.hasGeoQuery();
}
catch(e) {
return false;
}
},
explain(cursor) {
return `The selector contained $where or $near. Remove these operators.`;
},
},
badSort: {
test(cursor) {
if (!cursor.options.sort) {
return false;
}
try {
let matcher = new Minimongo.Matcher(cursor.selector),
sorter = new Minimongo.Sorter(cursor.options.sort, { matcher })
;
}
catch(e) {
return true;
}
},
explain(cursor) {
return `Minimongo couldn't compile the sort. Check your syntax and make sure you aren't sorting by $natural.`;
},
},
},
}.initialize();
export { Analyze };