forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodeintelbylanguage.go
More file actions
77 lines (64 loc) · 1.96 KB
/
codeintelbylanguage.go
File metadata and controls
77 lines (64 loc) · 1.96 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
package adminanalytics
import (
"context"
"fmt"
"time"
"github.com/sourcegraph/sourcegraph/internal/database"
)
type CodeIntelByLanguage struct {
Language_ string `json:"language"`
Precision_ string `json:"precision"`
Count_ float64 `json:"count"`
}
func (s *CodeIntelByLanguage) Language() string { return s.Language_ }
func (s *CodeIntelByLanguage) Precision() string { return s.Precision_ }
func (s *CodeIntelByLanguage) Count() float64 { return s.Count_ }
func GetCodeIntelByLanguage(ctx context.Context, db database.DB, cache bool, dateRange string) ([]*CodeIntelByLanguage, error) {
cacheKey := fmt.Sprintf(`CodeIntelByLanguage:%s`, dateRange)
if cache == true {
if nodes, err := getArrayFromCache[CodeIntelByLanguage](cacheKey); err == nil {
return nodes, nil
}
}
now := time.Now()
from, err := getFromDate(dateRange, now)
if err != nil {
return nil, err
}
rows, err := db.QueryContext(ctx, `
SELECT language, precision, COUNT(*) AS count
FROM (
SELECT argument->>'languageId' AS language, CASE WHEN name LIKE '%search%' THEN 'search-based' ELSE 'precise' END AS precision
FROM event_logs
WHERE
timestamp BETWEEN $1 AND $2 AND
name IN (
'codeintel.searchDefinitions',
'codeintel.searchDefinitions.xrepo',
'codeintel.searchReferences',
'codeintel.searchReferences.xrepo',
'codeintel.lsifDefinitions',
'codeintel.lsifDefinitions.xrepo',
'codeintel.lsifReferences',
'codeintel.lsifReferences.xrepo'
)
) sub
GROUP BY language, precision;
`, from.Format(time.RFC3339), now.Format(time.RFC3339))
if err != nil {
return nil, err
}
defer rows.Close()
items := []*CodeIntelByLanguage{}
for rows.Next() {
var item CodeIntelByLanguage
if err := rows.Scan(&item.Language_, &item.Precision_, &item.Count_); err != nil {
return nil, err
}
items = append(items, &item)
}
if _, err := setArrayToCache(cacheKey, items); err != nil {
return nil, err
}
return items, nil
}