forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodeinsights.go
More file actions
82 lines (68 loc) · 1.64 KB
/
codeinsights.go
File metadata and controls
82 lines (68 loc) · 1.64 KB
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
package adminanalytics
import (
"context"
"github.com/sourcegraph/sourcegraph/internal/database"
)
type CodeInsights struct {
DateRange string
Grouping string
DB database.DB
Cache bool
}
// Insights:Hovers
func (c *CodeInsights) InsightHovers() (*AnalyticsFetcher, error) {
nodesQuery, summaryQuery, err := makeEventLogsQueries(
c.DateRange,
c.Grouping,
[]string{"InsightHover"},
)
if err != nil {
return nil, err
}
return &AnalyticsFetcher{
db: c.DB,
dateRange: c.DateRange,
grouping: c.Grouping,
nodesQuery: nodesQuery,
summaryQuery: summaryQuery,
group: "Insights:InsightHovers",
cache: c.Cache,
}, nil
}
// Insights:DataPointClicks
func (c *CodeInsights) InsightDataPointClicks() (*AnalyticsFetcher, error) {
nodesQuery, summaryQuery, err := makeEventLogsQueries(
c.DateRange,
c.Grouping,
[]string{"InsightDataPointClick"},
)
if err != nil {
return nil, err
}
return &AnalyticsFetcher{
db: c.DB,
dateRange: c.DateRange,
grouping: c.Grouping,
nodesQuery: nodesQuery,
summaryQuery: summaryQuery,
group: "Insights:InsightDataPointClicks",
cache: c.Cache,
}, nil
}
// Insights caching job entrypoint
func (c *CodeInsights) CacheAll(ctx context.Context) error {
fetcherBuilders := []func() (*AnalyticsFetcher, error){c.InsightHovers, c.InsightDataPointClicks}
for _, buildFetcher := range fetcherBuilders {
fetcher, err := buildFetcher()
if err != nil {
return err
}
if _, err := fetcher.Nodes(ctx); err != nil {
return err
}
if _, err := fetcher.Summary(ctx); err != nil {
return err
}
}
return nil
}