forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload_handler.go
More file actions
89 lines (76 loc) · 2.54 KB
/
upload_handler.go
File metadata and controls
89 lines (76 loc) · 2.54 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
83
84
85
86
87
88
89
package uploads
import (
"context"
"github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types"
"github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/internal/store"
"github.com/sourcegraph/sourcegraph/internal/uploadhandler"
)
type UploadMetadata struct {
RepositoryID int
Commit string
Root string
Indexer string
IndexerVersion string
AssociatedIndexID int
}
type uploadHandlerShim struct {
store.Store
}
func (s *Service) UploadHandlerStore() uploadhandler.DBStore[UploadMetadata] {
return &uploadHandlerShim{s.store}
}
func (s *uploadHandlerShim) Transact(ctx context.Context) (uploadhandler.DBStore[UploadMetadata], error) {
tx, err := s.Store.Transact(ctx)
if err != nil {
return nil, err
}
return &uploadHandlerShim{tx}, nil
}
func (s *uploadHandlerShim) InsertUpload(ctx context.Context, upload uploadhandler.Upload[UploadMetadata]) (int, error) {
var associatedIndexID *int
if upload.Metadata.AssociatedIndexID != 0 {
associatedIndexID = &upload.Metadata.AssociatedIndexID
}
return s.Store.InsertUpload(ctx, types.Upload{
ID: upload.ID,
State: upload.State,
NumParts: upload.NumParts,
UploadedParts: upload.UploadedParts,
UploadSize: upload.UploadSize,
UncompressedSize: upload.UncompressedSize,
RepositoryID: upload.Metadata.RepositoryID,
Commit: upload.Metadata.Commit,
Root: upload.Metadata.Root,
Indexer: upload.Metadata.Indexer,
IndexerVersion: upload.Metadata.IndexerVersion,
AssociatedIndexID: associatedIndexID,
})
}
func (s *uploadHandlerShim) GetUploadByID(ctx context.Context, uploadID int) (uploadhandler.Upload[UploadMetadata], bool, error) {
upload, ok, err := s.Store.GetUploadByID(ctx, uploadID)
if err != nil {
return uploadhandler.Upload[UploadMetadata]{}, false, err
}
if !ok {
return uploadhandler.Upload[UploadMetadata]{}, false, nil
}
u := uploadhandler.Upload[UploadMetadata]{
ID: upload.ID,
State: upload.State,
NumParts: upload.NumParts,
UploadedParts: upload.UploadedParts,
UploadSize: upload.UploadSize,
UncompressedSize: upload.UncompressedSize,
Metadata: UploadMetadata{
RepositoryID: upload.RepositoryID,
Commit: upload.Commit,
Root: upload.Root,
Indexer: upload.Indexer,
IndexerVersion: upload.IndexerVersion,
},
}
if upload.AssociatedIndexID != nil {
u.Metadata.AssociatedIndexID = *upload.AssociatedIndexID
}
return u, true, nil
}