forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservices.go
More file actions
61 lines (53 loc) · 2.4 KB
/
services.go
File metadata and controls
61 lines (53 loc) · 2.4 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
package codeintel
import (
"github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing"
"github.com/sourcegraph/sourcegraph/internal/codeintel/codenav"
"github.com/sourcegraph/sourcegraph/internal/codeintel/dependencies"
"github.com/sourcegraph/sourcegraph/internal/codeintel/policies"
"github.com/sourcegraph/sourcegraph/internal/codeintel/ranking"
codeintelshared "github.com/sourcegraph/sourcegraph/internal/codeintel/shared"
"github.com/sourcegraph/sourcegraph/internal/codeintel/shared/gitserver"
"github.com/sourcegraph/sourcegraph/internal/codeintel/uploads"
"github.com/sourcegraph/sourcegraph/internal/database"
"github.com/sourcegraph/sourcegraph/internal/memo"
"github.com/sourcegraph/sourcegraph/internal/observation"
)
type Services struct {
AutoIndexingService *autoindexing.Service
CodenavService *codenav.Service
DependenciesService *dependencies.Service
PoliciesService *policies.Service
RankingService *ranking.Service
UploadsService *uploads.Service
}
type Databases struct {
DB database.DB
CodeIntelDB codeintelshared.CodeIntelDB
}
// GetServices creates or returns an already-initialized codeintel service collection.
// If the service collection is not yet initialized, a new one will be constructed using
// the given database handles.
func GetServices(dbs Databases) (Services, error) {
return initServicesMemo.Init(dbs)
}
var initServicesMemo = memo.NewMemoizedConstructorWithArg(func(dbs Databases) (Services, error) {
db, codeIntelDB := dbs.DB, dbs.CodeIntelDB
gitserverClient := gitserver.New(db, scopedContext("gitserver"))
uploadsSvc := uploads.GetService(db, codeIntelDB, gitserverClient)
dependenciesSvc := dependencies.GetService(db, gitserverClient)
policiesSvc := policies.GetService(db, uploadsSvc, gitserverClient)
autoIndexingSvc := autoindexing.GetService(db, uploadsSvc, dependenciesSvc, policiesSvc, gitserverClient)
codenavSvc := codenav.GetService(db, codeIntelDB, uploadsSvc, gitserverClient)
rankingSvc := ranking.GetService(db, uploadsSvc, gitserverClient)
return Services{
AutoIndexingService: autoIndexingSvc,
CodenavService: codenavSvc,
DependenciesService: dependenciesSvc,
PoliciesService: policiesSvc,
RankingService: rankingSvc,
UploadsService: uploadsSvc,
}, nil
})
func scopedContext(component string) *observation.Context {
return observation.ScopedContext("codeintel", "worker", component)
}