Skip to content

Commit fbd2c41

Browse files
committed
use the same context for loadAllChanges whilst loading an object from the store
1 parent 0aeada4 commit fbd2c41

File tree

5 files changed

+20
-19
lines changed

5 files changed

+20
-19
lines changed

src/data/model/immutable/HashedObject.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,9 @@ abstract class HashedObject {
437437

438438
static collectDirectSubobjects(path: string, value: any, subobjects: Map<string, HashedObject>) {
439439

440+
//console.log('called collectDirectSubobjects() w/path', path, 'subobjects: ', subobjects.size);
441+
//console.log(new Error().stack);
442+
440443
let typ = typeof(value);
441444

442445
// We're only concerned with 'object' typed stuff, since scalars, strings, etc. cannot yield
@@ -1062,12 +1065,12 @@ abstract class HashedObject {
10621065
return this._boundToStore;
10631066
}
10641067

1065-
async loadAllChanges(loadBatchSize=128) {
1068+
async loadAllChanges(loadBatchSize=128, context = new Context()) {
10661069

10671070
const subobjs = new Set(this.getDirectSubObjects().values());
10681071

10691072
for (const subobj of subobjs.values()) {
1070-
await subobj.loadAllChanges(loadBatchSize);
1073+
await subobj.loadAllChanges(loadBatchSize, context);
10711074
}
10721075
}
10731076
}

src/data/model/mutable/MutableObject.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ abstract class MutableObject extends HashedObject {
220220

221221
}
222222

223-
async loadAllChanges(batchSize=128) {
223+
async loadAllChanges(batchSize=128, context = new Context()) {
224224

225-
await super.loadAllChanges(batchSize);
225+
await super.loadAllChanges(batchSize, context);
226226

227227
let results = await this.getStore()
228228
.loadByReference(
@@ -231,7 +231,8 @@ abstract class MutableObject extends HashedObject {
231231
{
232232
order: 'asc',
233233
limit: batchSize
234-
});
234+
},
235+
context);
235236

236237
while (results.objects.length > 0) {
237238

@@ -249,7 +250,8 @@ abstract class MutableObject extends HashedObject {
249250
order: 'asc',
250251
limit: batchSize,
251252
start: results.end
252-
});
253+
},
254+
context);
253255
}
254256
}
255257

src/storage/store/Store.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ class Store {
504504
}
505505

506506
//console.log('+++ loading changes for ' + hash + ' ', new Error().stack);
507-
await object.loadAllChanges();
507+
await object.loadAllChanges(undefined, context);
508508

509509
/*for (const subobj of context.objects.values()) {
510510
if (watchForChanges) {
@@ -588,26 +588,26 @@ class Store {
588588
return obj;
589589
}
590590

591-
async loadByClass(className: string, params?: LoadParams) : Promise<LoadResults> {
591+
async loadByClass(className: string, params?: LoadParams, context = new Context()) : Promise<LoadResults> {
592592

593593
let searchResults = await this.backend.searchByClass(className, params);
594594

595-
return this.loadSearchResults(searchResults);
595+
return this.loadSearchResults(searchResults, context);
596596

597597
}
598598

599-
async loadByReference(referringPath: string, referencedHash: Hash, params?: LoadParams) : Promise<LoadResults> {
599+
async loadByReference(referringPath: string, referencedHash: Hash, params?: LoadParams, context = new Context()) : Promise<LoadResults> {
600600

601601
let searchResults = await this.backend.searchByReference(referringPath, referencedHash, params);
602602

603-
return this.loadSearchResults(searchResults);
603+
return this.loadSearchResults(searchResults, context);
604604
}
605605

606-
async loadByReferencingClass(referringClassName: string, referringPath: string, referencedHash: Hash, params?: LoadParams) : Promise<LoadResults> {
606+
async loadByReferencingClass(referringClassName: string, referringPath: string, referencedHash: Hash, params?: LoadParams, context = new Context()) : Promise<LoadResults> {
607607

608608
let searchResults = await this.backend.searchByReferencingClass(referringClassName, referringPath, referencedHash, params);
609609

610-
return this.loadSearchResults(searchResults);
610+
return this.loadSearchResults(searchResults, context);
611611
}
612612

613613
async loadOpHeader(opHash: Hash): Promise<OpHeader | undefined> {
@@ -659,9 +659,7 @@ class Store {
659659
return literal;
660660
}*/
661661

662-
private async loadSearchResults(searchResults: BackendSearchResults) : Promise<{objects: Array<HashedObject>, start?: string, end?: string}> {
663-
664-
let context = new Context();
662+
private async loadSearchResults(searchResults: BackendSearchResults, context = new Context()) : Promise<{objects: Array<HashedObject>, start?: string, end?: string}> {
665663

666664
let objects = [] as Array<HashedObject>;
667665

test/data/collections/causal/reference.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ describeProxy('[CRF] Causal references', () => {
8585

8686
await mutWritersClone.save();
8787

88-
console.log('FINAL LOADING!')
89-
9088
let refClone = await store.load(ref.hash()) as CausalReference<string>;
9189

9290
expect (refClone.getValue()).toEqual('2');

test/data/collections/causal/set.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ describeProxy('[CST] Causal sets', () => {
118118

119119
done();
120120

121-
});
121+
}, 10000);
122122

123123
test('[CST03] Causal set redo', async (done) => {
124124
let store = new Store(new IdbBackend('CST02 - ' + new RNGImpl().randomHexString(128)));

0 commit comments

Comments
 (0)