11import { Memento } from 'vscode'
22import { SortDefinition , sortExperiments } from './sortBy'
3- import { FilterDefinition , filterExperiment , getFilterId } from './filterBy'
3+ import { FilterDefinition , getFilterId } from './filterBy'
4+ import { collectFiltered , collectUnfiltered } from './filterBy/collect'
45import {
56 collectAddRemoveCommitsDetails ,
67 collectBranches ,
@@ -27,7 +28,7 @@ import {
2728 GitRemoteStatus ,
2829 RunningExperiment
2930} from '../webview/contract'
30- import { definedAndNonEmpty , reorderListSubset } from '../../util/array'
31+ import { reorderListSubset } from '../../util/array'
3132import {
3233 Executor ,
3334 ExpShowOutput ,
@@ -409,31 +410,27 @@ export class ExperimentsModel extends ModelWithPersistence {
409410 }
410411
411412 public getRowData ( ) {
412- const commitsBySha : { [ sha : string ] : Commit } = { }
413- for ( const commit of this . commits ) {
414- commitsBySha [ commit . sha as string ] = commit
415- }
413+ const commitsBySha = this . applyFiltersToCommits ( )
416414
417- return [
418- { branch : undefined , ...this . addDetails ( this . workspace ) } ,
419- ...this . rowOrder . map ( ( { branch, sha } ) => {
420- const commit = { ...commitsBySha [ sha ] , branch }
421- const experiments = this . getExperimentsByCommit ( commit )
422- const commitWithSelectedAndStarred = this . addDetails ( commit )
423-
424- if ( ! definedAndNonEmpty ( experiments ) ) {
425- return commitWithSelectedAndStarred
426- }
427-
428- return {
429- ...commitWithSelectedAndStarred ,
430- subRows : experiments . filter (
431- ( experiment : Experiment ) =>
432- ! ! filterExperiment ( this . getFilters ( ) , experiment )
433- )
434- }
435- } )
415+ const rows : Commit [ ] = [
416+ { branch : undefined , ...this . addDetails ( this . workspace ) }
436417 ]
418+ for ( const { branch, sha } of this . rowOrder ) {
419+ const commit = commitsBySha [ sha ]
420+ if ( ! commit ) {
421+ continue
422+ }
423+ if ( commit . subRows ) {
424+ commit . subRows = commit . subRows . map ( experiment => ( {
425+ ...experiment ,
426+ branch
427+ } ) )
428+ }
429+
430+ rows . push ( { ...commit , branch } )
431+ }
432+
433+ return rows
437434 }
438435
439436 public getHasMoreCommits ( ) {
@@ -461,6 +458,10 @@ export class ExperimentsModel extends ModelWithPersistence {
461458 return filtered . length
462459 }
463460
461+ public getRecordCount ( ) {
462+ return this . getCombinedList ( ) . length
463+ }
464+
464465 public getCombinedList ( ) {
465466 return [ this . workspace , ...this . commits , ...this . getExperimentsAndQueued ( ) ]
466467 }
@@ -530,10 +531,14 @@ export class ExperimentsModel extends ModelWithPersistence {
530531 private getFilteredExperiments ( ) {
531532 const acc : Experiment [ ] = [ ]
532533
533- for ( const experiment of this . getExperiments ( ) ) {
534- if ( ! filterExperiment ( this . getFilters ( ) , experiment ) ) {
535- acc . push ( experiment )
536- }
534+ for ( const commit of this . commits ) {
535+ const experiments = this . getExperimentsByCommit ( commit )
536+ collectFiltered (
537+ acc ,
538+ this . addDetails ( commit ) ,
539+ experiments ,
540+ this . getFilters ( )
541+ )
537542 }
538543
539544 return acc
@@ -543,10 +548,7 @@ export class ExperimentsModel extends ModelWithPersistence {
543548 const experiments = this . experimentsByCommit
544549 . get ( commit . id )
545550 ?. map ( originalExperiment => {
546- const experiment = {
547- ...this . addDetails ( originalExperiment ) ,
548- branch : commit . branch
549- }
551+ const experiment = this . addDetails ( originalExperiment )
550552
551553 this . addRemoteStatus ( experiment )
552554
@@ -697,4 +699,25 @@ export class ExperimentsModel extends ModelWithPersistence {
697699 }
698700 return uniqueStatus
699701 }
702+
703+ private applyFiltersToCommits ( ) {
704+ const commitsBySha : { [ sha : string ] : Commit } = { }
705+ for ( const commit of this . commits ) {
706+ const commitWithSelectedAndStarred = this . addDetails ( commit )
707+ const experiments = this . getExperimentsByCommit (
708+ commitWithSelectedAndStarred
709+ )
710+ const unfilteredCommit = collectUnfiltered (
711+ commitWithSelectedAndStarred ,
712+ experiments ,
713+ this . getFilters ( )
714+ )
715+ if ( ! unfilteredCommit ) {
716+ continue
717+ }
718+
719+ commitsBySha [ commit . sha as string ] = unfilteredCommit
720+ }
721+ return commitsBySha
722+ }
700723}
0 commit comments