-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
db.go
70 lines (61 loc) · 1.5 KB
/
db.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
package yolosvc
import (
"context"
"time"
// for sqlite inmemory test db
_ "github.com/mattn/go-sqlite3"
"berty.tech/yolo/v2/go/pkg/yolopb"
"berty.tech/yolo/v2/go/pkg/yolostore"
"go.uber.org/zap"
)
func (svc *service) saveBatch(ctx context.Context, batch *yolopb.Batch) error {
if batch.Empty() {
return nil
}
batch.Optimize() // remove duplicates
{
log := svc.logger.With()
if l := len(batch.Projects); l > 0 {
log = log.With(zap.Int("projects", l))
}
if l := len(batch.Releases); l > 0 {
log = log.With(zap.Int("releases", l))
}
if l := len(batch.MergeRequests); l > 0 {
log = log.With(zap.Int("merge_requests", l))
}
if l := len(batch.Artifacts); l > 0 {
log = log.With(zap.Int("artifacts", l))
}
if l := len(batch.Builds); l > 0 {
log = log.With(zap.Int("builds", l))
}
if l := len(batch.Commits); l > 0 {
log = log.With(zap.Int("commits", l))
}
if l := len(batch.Entities); l > 0 {
log = log.With(zap.Int("entities", l))
}
log.Debug("saveBatch")
}
err := svc.store.SaveBatch(batch)
if err != nil {
return err
}
svc.clearCache.Set()
return nil
}
func lastBuildCreatedTime(ctx context.Context, store yolostore.Store, driver yolopb.Driver) (time.Time, error) {
build, err := store.GetLastBuild(driver)
if err != nil {
return time.Time{}, err
}
if build.FinishedAt == nil {
return time.Time{}, nil
}
since := *build.FinishedAt
if !since.IsZero() {
since = since.Add(time.Second) // in order to skip the last one
}
return since, nil
}