-
Notifications
You must be signed in to change notification settings - Fork 111
/
catalog.go
91 lines (79 loc) · 2.11 KB
/
catalog.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package catalog
import (
"context"
"sync"
"time"
"github.com/rilldata/rill/runtime/drivers"
"github.com/rilldata/rill/runtime/pkg/dag"
"go.uber.org/zap"
)
type Service struct {
Catalog drivers.CatalogStore
Repo drivers.RepoStore
Olap drivers.OLAPStore
RegistryStore drivers.RegistryStore
InstID string
logger *zap.Logger
Meta *MigrationMeta
}
func NewService(
catalog drivers.CatalogStore,
repo drivers.RepoStore,
olap drivers.OLAPStore,
registry drivers.RegistryStore,
instID string,
logger *zap.Logger,
m *MigrationMeta,
) *Service {
if logger == nil {
logger = zap.NewNop()
}
return &Service{
Catalog: catalog,
Repo: repo,
Olap: olap,
RegistryStore: registry,
InstID: instID,
logger: logger,
Meta: m,
}
}
func (s *Service) FindEntries(ctx context.Context, typ drivers.ObjectType) ([]*drivers.CatalogEntry, error) {
entries, err := s.Catalog.FindEntries(ctx, s.InstID, typ)
if err != nil {
return nil, err
}
for _, entry := range entries {
s.Meta.fillDAGInEntry(entry)
}
return entries, nil
}
func (s *Service) FindEntry(ctx context.Context, name string) (*drivers.CatalogEntry, error) {
entry, err := s.Catalog.FindEntry(ctx, s.InstID, name)
if err != nil {
return nil, err
}
s.Meta.fillDAGInEntry(entry)
return entry, nil
}
type MigrationMeta struct {
// temporary information. should this be persisted into olap?
// LastMigration stores the last time migrate was run. Used to filter out repos that didnt change since this time
LastMigration time.Time
dag *dag.DAG
// used to get path when we only have name. happens when we get name from DAG
// TODO: should we add path to the DAG instead
NameToPath map[string]string
hasMigrated bool
lock sync.Mutex
}
func NewMigrationMeta() *MigrationMeta {
return &MigrationMeta{
dag: dag.NewDAG(),
NameToPath: make(map[string]string),
}
}
func (m *MigrationMeta) fillDAGInEntry(entry *drivers.CatalogEntry) {
entry.Children = m.dag.GetChildren(normalizeName(entry.Name))
entry.Parents = m.dag.GetParents(normalizeName(entry.Name))
}