1+ import { commits } from './ontologies/commits.js' ;
12import { EventManager } from './EventManager.js' ;
23import type { Agent } from './agent.js' ;
34import { Client } from './client.js' ;
@@ -371,19 +372,25 @@ export class Resource<C extends OptionalClass = any> {
371372 public async getHistory (
372373 progressCallback ?: ( percentage : number ) => void ,
373374 ) : 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 ( ) ;
380383
381384 const builtVersions : Version [ ] = [ ] ;
382385
386+ if ( ! commitSubjects ) {
387+ return builtVersions ;
388+ }
389+
383390 let previousResource = new Resource ( this . subject ) ;
384391
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 ] ) ;
387394 const parsedCommit = parseCommitResource ( commitResource ) ;
388395 const builtResource = applyCommitToResource (
389396 previousResource . clone ( ) ,
@@ -397,7 +404,7 @@ export class Resource<C extends OptionalClass = any> {
397404
398405 // Every 30 cycles we report the progress
399406 if ( progressCallback && i % 30 === 0 ) {
400- progressCallback ( Math . round ( ( i / commits . length ) * 100 ) ) ;
407+ progressCallback ( Math . round ( ( i / commitSubjects . length ) * 100 ) ) ;
401408 await WaitForImmediate ( ) ;
402409 }
403410 }
0 commit comments