MCPcopy
hub / github.com/strongloop/loopback / tryReplicate

Function tryReplicate

lib/persisted-model.js:1205–1363  ·  view source on GitHub ↗
(sourceModel, targetModel, since, options, callback)

Source from the content-addressed store, hash-verified

1203 };
1204
1205 function tryReplicate(sourceModel, targetModel, since, options, callback) {
1206 const Change = sourceModel.getChangeModel();
1207 const TargetChange = targetModel.getChangeModel();
1208 const changeTrackingEnabled = Change && TargetChange;
1209 let replicationChunkSize = REPLICATION_CHUNK_SIZE;
1210
1211 if (sourceModel.settings && sourceModel.settings.replicationChunkSize) {
1212 replicationChunkSize = sourceModel.settings.replicationChunkSize;
1213 }
1214
1215 assert(
1216 changeTrackingEnabled,
1217 'You must enable change tracking before replicating',
1218 );
1219
1220 let diff, updates, newSourceCp, newTargetCp;
1221
1222 const tasks = [
1223 checkpoints,
1224 getSourceChanges,
1225 getDiffFromTarget,
1226 createSourceUpdates,
1227 bulkUpdate,
1228 ];
1229
1230 async.waterfall(tasks, done);
1231
1232 function getSourceChanges(cb) {
1233 utils.downloadInChunks(
1234 options.filter,
1235 replicationChunkSize,
1236 function(filter, pagingCallback) {
1237 sourceModel.changes(since.source, filter, pagingCallback);
1238 },
1239 debug.enabled ? log : cb,
1240 );
1241
1242 function log(err, result) {
1243 if (err) return cb(err);
1244 debug('\tusing source changes');
1245 result.forEach(function(it) { debug('\t\t%j', it); });
1246 cb(err, result);
1247 }
1248 }
1249
1250 function getDiffFromTarget(sourceChanges, cb) {
1251 utils.uploadInChunks(
1252 sourceChanges,
1253 replicationChunkSize,
1254 function(smallArray, chunkCallback) {
1255 return targetModel.diff(since.target, smallArray, chunkCallback);
1256 },
1257 debug.enabled ? log : cb,
1258 );
1259
1260 function log(err, result) {
1261 if (err) return cb(err);
1262 if (result.conflicts && result.conflicts.length) {

Callers 1

runFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…