1
+ import { commits } from './ontologies/commits.js' ;
1
2
import { EventManager } from './EventManager.js' ;
2
3
import type { Agent } from './agent.js' ;
3
4
import { Client } from './client.js' ;
@@ -371,19 +372,25 @@ export class Resource<C extends OptionalClass = any> {
371
372
public async getHistory (
372
373
progressCallback ?: ( percentage : number ) => void ,
373
374
) : Promise < Version [ ] > {
374
- const commitsCollection = await this . store . fetchResourceFromServer (
375
- this . getCommitsCollectionSubject ( ) ,
376
- ) ;
377
- const commits = commitsCollection . get (
378
- properties . collection . members ,
379
- ) as string [ ] ;
375
+ const commitsCollection = await new CollectionBuilder ( this . store )
376
+ . setPageSize ( 9999 )
377
+ . setProperty ( commits . properties . subject )
378
+ . setValue ( this . subject )
379
+ . setSortBy ( commits . properties . createdAt )
380
+ . buildAndFetch ( ) ;
381
+
382
+ const commitSubjects = await commitsCollection . getAllMembers ( ) ;
380
383
381
384
const builtVersions : Version [ ] = [ ] ;
382
385
386
+ if ( ! commitSubjects ) {
387
+ return builtVersions ;
388
+ }
389
+
383
390
let previousResource = new Resource ( this . subject ) ;
384
391
385
- for ( let i = 0 ; i < commits . length ; i ++ ) {
386
- const commitResource = await this . store . getResource ( commits [ i ] ) ;
392
+ for ( let i = 0 ; i < commitSubjects . length ; i ++ ) {
393
+ const commitResource = await this . store . getResource ( commitSubjects [ i ] ) ;
387
394
const parsedCommit = parseCommitResource ( commitResource ) ;
388
395
const builtResource = applyCommitToResource (
389
396
previousResource . clone ( ) ,
@@ -397,7 +404,7 @@ export class Resource<C extends OptionalClass = any> {
397
404
398
405
// Every 30 cycles we report the progress
399
406
if ( progressCallback && i % 30 === 0 ) {
400
- progressCallback ( Math . round ( ( i / commits . length ) * 100 ) ) ;
407
+ progressCallback ( Math . round ( ( i / commitSubjects . length ) * 100 ) ) ;
401
408
await WaitForImmediate ( ) ;
402
409
}
403
410
}
0 commit comments