aboutsummaryrefslogblamecommitdiffstats
path: root/entity/dag/clock.go
blob: f773e15c4ef831cde04d9ced66285a831cb39de5 (plain) (tree)
1
2
3
4
5
6
7
8




             

                                    
                                               



                                                             
                                                
                                  

                                                                                         




                                                                    
                                               
                                                  
                                          


                                                                              
                         
                                          


                  
package dag

import (
	"fmt"

	"golang.org/x/sync/errgroup"

	"github.com/git-bug/git-bug/repository"
)

// ClockLoader is the repository.ClockLoader for Entity
func ClockLoader(defs ...Definition) repository.ClockLoader {
	clocks := make([]string, 0, len(defs)*2)
	for _, def := range defs {
		clocks = append(clocks, fmt.Sprintf(creationClockPattern, def.Namespace))
		clocks = append(clocks, fmt.Sprintf(editClockPattern, def.Namespace))
	}

	return repository.ClockLoader{
		Clocks: clocks,
		Witnesser: func(repo repository.ClockedRepo) error {
			var errG errgroup.Group
			for _, def := range defs {
				def := def
				errG.Go(func() error {
					return ReadAllClocksNoCheck(def, repo)
				})
			}
			return errG.Wait()
		},
	}
}