File tree 5 files changed +43
-22
lines changed
5 files changed +43
-22
lines changed Original file line number Diff line number Diff line change @@ -18,13 +18,24 @@ const handleCallback = require('../utils').handleCallback;
18
18
const indexInformationDb = require ( './db_ops' ) . indexInformation ;
19
19
const isObject = require ( '../utils' ) . isObject ;
20
20
const Long = require ( 'mongodb-core' ) . BSON . Long ;
21
- const makeLazyLoader = require ( '../utils' ) . makeLazyLoader ;
22
21
const MongoError = require ( 'mongodb-core' ) . MongoError ;
23
22
const ReadPreference = require ( 'mongodb-core' ) . ReadPreference ;
24
23
const toError = require ( '../utils' ) . toError ;
25
24
26
- const loadCollection = makeLazyLoader ( `${ __dirname } /../collection` ) ;
27
- const loadDb = makeLazyLoader ( `${ __dirname } /../db` ) ;
25
+ let collection ;
26
+ function loadCollection ( ) {
27
+ if ( ! collection ) {
28
+ collection = require ( '../collection' ) ;
29
+ }
30
+ return collection ;
31
+ }
32
+ let db ;
33
+ function loadDb ( ) {
34
+ if ( ! db ) {
35
+ db = require ( '../db' ) ;
36
+ }
37
+ return db ;
38
+ }
28
39
29
40
/**
30
41
* Group function helper
Original file line number Diff line number Diff line change 3
3
const buildCountCommand = require ( './collection_ops' ) . buildCountCommand ;
4
4
const formattedOrderClause = require ( '../utils' ) . formattedOrderClause ;
5
5
const handleCallback = require ( '../utils' ) . handleCallback ;
6
- const makeLazyLoader = require ( '../utils' ) . makeLazyLoader ;
7
6
const MongoError = require ( 'mongodb-core' ) . MongoError ;
8
7
const push = Array . prototype . push ;
9
8
10
- const loadCursor = makeLazyLoader ( `${ __dirname } /../cursor` ) ;
9
+ let cursor ;
10
+ function loadCursor ( ) {
11
+ if ( ! cursor ) {
12
+ cursor = require ( '../cursor' ) ;
13
+ }
14
+ return cursor ;
15
+ }
11
16
12
17
/**
13
18
* Get the count of documents for this cursor.
Original file line number Diff line number Diff line change @@ -6,7 +6,6 @@ const resolveReadPreference = require('../utils').resolveReadPreference;
6
6
const crypto = require ( 'crypto' ) ;
7
7
const debugOptions = require ( '../utils' ) . debugOptions ;
8
8
const handleCallback = require ( '../utils' ) . handleCallback ;
9
- const makeLazyLoader = require ( '../utils' ) . makeLazyLoader ;
10
9
const MongoError = require ( 'mongodb-core' ) . MongoError ;
11
10
const parseIndexOptions = require ( '../utils' ) . parseIndexOptions ;
12
11
const ReadPreference = require ( 'mongodb-core' ) . ReadPreference ;
@@ -18,8 +17,20 @@ const findOne = require('./collection_ops').findOne;
18
17
const remove = require ( './collection_ops' ) . remove ;
19
18
const updateOne = require ( './collection_ops' ) . updateOne ;
20
19
21
- const loadCollection = makeLazyLoader ( `${ __dirname } /../collection` ) ;
22
- const loadDb = makeLazyLoader ( `${ __dirname } /../db` ) ;
20
+ let collection ;
21
+ function loadCollection ( ) {
22
+ if ( ! collection ) {
23
+ collection = require ( '../collection' ) ;
24
+ }
25
+ return collection ;
26
+ }
27
+ let db ;
28
+ function loadDb ( ) {
29
+ if ( ! db ) {
30
+ db = require ( '../db' ) ;
31
+ }
32
+ return db ;
33
+ }
23
34
24
35
const debugFields = [
25
36
'authSource' ,
Original file line number Diff line number Diff line change 3
3
const authenticate = require ( '../authenticate' ) ;
4
4
const deprecate = require ( 'util' ) . deprecate ;
5
5
const Logger = require ( 'mongodb-core' ) . Logger ;
6
- const makeLazyLoader = require ( '../utils' ) . makeLazyLoader ;
7
6
const MongoError = require ( 'mongodb-core' ) . MongoError ;
8
7
const Mongos = require ( '../topologies/mongos' ) ;
9
8
const parse = require ( 'mongodb-core' ) . parseConnectionString ;
@@ -12,7 +11,13 @@ const ReplSet = require('../topologies/replset');
12
11
const Server = require ( '../topologies/server' ) ;
13
12
const ServerSessionPool = require ( 'mongodb-core' ) . Sessions . ServerSessionPool ;
14
13
15
- const loadClient = makeLazyLoader ( `${ __dirname } /../mongo_client` ) ;
14
+ let client ;
15
+ function loadClient ( ) {
16
+ if ( ! client ) {
17
+ client = require ( '../mongo_client' ) ;
18
+ }
19
+ return client ;
20
+ }
16
21
17
22
const monitoringEvents = [
18
23
'timeout' ,
Original file line number Diff line number Diff line change @@ -694,16 +694,6 @@ function deprecateOptions(config, fn) {
694
694
return deprecated ;
695
695
}
696
696
697
- function makeLazyLoader ( modulePath ) {
698
- let mod ;
699
- return function lazyLoad ( ) {
700
- if ( ! mod ) {
701
- mod = require ( modulePath ) ;
702
- }
703
- return mod ;
704
- } ;
705
- }
706
-
707
697
module . exports = {
708
698
filterOptions,
709
699
mergeOptions,
@@ -729,6 +719,5 @@ module.exports = {
729
719
isPromiseLike,
730
720
decorateWithCollation,
731
721
decorateWithReadConcern,
732
- deprecateOptions,
733
- makeLazyLoader
722
+ deprecateOptions
734
723
} ;
You can’t perform that action at this time.
0 commit comments