mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 17:31:43 +00:00
feat: Add experimental feature to control commit graph updates (#63870)
This commit is contained in:
parent
2947657755
commit
8597286c8f
@ -76,10 +76,10 @@ type MockStore struct {
|
||||
// GetAuditLogsForUploadFunc is an instance of a mock function object
|
||||
// controlling the behavior of the method GetAuditLogsForUpload.
|
||||
GetAuditLogsForUploadFunc *StoreGetAuditLogsForUploadFunc
|
||||
// GetCommitDateForOldestUploadFunc is an instance of a mock function
|
||||
// GetCommitAndDateForOldestUploadFunc is an instance of a mock function
|
||||
// object controlling the behavior of the method
|
||||
// GetCommitDateForOldestUpload.
|
||||
GetCommitDateForOldestUploadFunc *StoreGetCommitDateForOldestUploadFunc
|
||||
// GetCommitAndDateForOldestUpload.
|
||||
GetCommitAndDateForOldestUploadFunc *StoreGetCommitAndDateForOldestUploadFunc
|
||||
// GetCommitGraphMetadataFunc is an instance of a mock function object
|
||||
// controlling the behavior of the method GetCommitGraphMetadata.
|
||||
GetCommitGraphMetadataFunc *StoreGetCommitGraphMetadataFunc
|
||||
@ -317,8 +317,8 @@ func NewMockStore() *MockStore {
|
||||
return
|
||||
},
|
||||
},
|
||||
GetCommitDateForOldestUploadFunc: &StoreGetCommitDateForOldestUploadFunc{
|
||||
defaultHook: func(context.Context, int) (r0 core.Option[time.Time], r1 error) {
|
||||
GetCommitAndDateForOldestUploadFunc: &StoreGetCommitAndDateForOldestUploadFunc{
|
||||
defaultHook: func(context.Context, int) (r0 core.Option[store.CommitWithDate], r1 error) {
|
||||
return
|
||||
},
|
||||
},
|
||||
@ -644,9 +644,9 @@ func NewStrictMockStore() *MockStore {
|
||||
panic("unexpected invocation of MockStore.GetAuditLogsForUpload")
|
||||
},
|
||||
},
|
||||
GetCommitDateForOldestUploadFunc: &StoreGetCommitDateForOldestUploadFunc{
|
||||
defaultHook: func(context.Context, int) (core.Option[time.Time], error) {
|
||||
panic("unexpected invocation of MockStore.GetCommitDateForOldestUpload")
|
||||
GetCommitAndDateForOldestUploadFunc: &StoreGetCommitAndDateForOldestUploadFunc{
|
||||
defaultHook: func(context.Context, int) (core.Option[store.CommitWithDate], error) {
|
||||
panic("unexpected invocation of MockStore.GetCommitAndDateForOldestUpload")
|
||||
},
|
||||
},
|
||||
GetCommitGraphMetadataFunc: &StoreGetCommitGraphMetadataFunc{
|
||||
@ -943,8 +943,8 @@ func NewMockStoreFrom(i store.Store) *MockStore {
|
||||
GetAuditLogsForUploadFunc: &StoreGetAuditLogsForUploadFunc{
|
||||
defaultHook: i.GetAuditLogsForUpload,
|
||||
},
|
||||
GetCommitDateForOldestUploadFunc: &StoreGetCommitDateForOldestUploadFunc{
|
||||
defaultHook: i.GetCommitDateForOldestUpload,
|
||||
GetCommitAndDateForOldestUploadFunc: &StoreGetCommitAndDateForOldestUploadFunc{
|
||||
defaultHook: i.GetCommitAndDateForOldestUpload,
|
||||
},
|
||||
GetCommitGraphMetadataFunc: &StoreGetCommitGraphMetadataFunc{
|
||||
defaultHook: i.GetCommitGraphMetadata,
|
||||
@ -2653,37 +2653,37 @@ func (c StoreGetAuditLogsForUploadFuncCall) Results() []interface{} {
|
||||
return []interface{}{c.Result0, c.Result1}
|
||||
}
|
||||
|
||||
// StoreGetCommitDateForOldestUploadFunc describes the behavior when the
|
||||
// GetCommitDateForOldestUpload method of the parent MockStore instance is
|
||||
// invoked.
|
||||
type StoreGetCommitDateForOldestUploadFunc struct {
|
||||
defaultHook func(context.Context, int) (core.Option[time.Time], error)
|
||||
hooks []func(context.Context, int) (core.Option[time.Time], error)
|
||||
history []StoreGetCommitDateForOldestUploadFuncCall
|
||||
// StoreGetCommitAndDateForOldestUploadFunc describes the behavior when the
|
||||
// GetCommitAndDateForOldestUpload method of the parent MockStore instance
|
||||
// is invoked.
|
||||
type StoreGetCommitAndDateForOldestUploadFunc struct {
|
||||
defaultHook func(context.Context, int) (core.Option[store.CommitWithDate], error)
|
||||
hooks []func(context.Context, int) (core.Option[store.CommitWithDate], error)
|
||||
history []StoreGetCommitAndDateForOldestUploadFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// GetCommitDateForOldestUpload delegates to the next hook function in the
|
||||
// queue and stores the parameter and result values of this invocation.
|
||||
func (m *MockStore) GetCommitDateForOldestUpload(v0 context.Context, v1 int) (core.Option[time.Time], error) {
|
||||
r0, r1 := m.GetCommitDateForOldestUploadFunc.nextHook()(v0, v1)
|
||||
m.GetCommitDateForOldestUploadFunc.appendCall(StoreGetCommitDateForOldestUploadFuncCall{v0, v1, r0, r1})
|
||||
// GetCommitAndDateForOldestUpload delegates to the next hook function in
|
||||
// the queue and stores the parameter and result values of this invocation.
|
||||
func (m *MockStore) GetCommitAndDateForOldestUpload(v0 context.Context, v1 int) (core.Option[store.CommitWithDate], error) {
|
||||
r0, r1 := m.GetCommitAndDateForOldestUploadFunc.nextHook()(v0, v1)
|
||||
m.GetCommitAndDateForOldestUploadFunc.appendCall(StoreGetCommitAndDateForOldestUploadFuncCall{v0, v1, r0, r1})
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// SetDefaultHook sets function that is called when the
|
||||
// GetCommitDateForOldestUpload method of the parent MockStore instance is
|
||||
// invoked and the hook queue is empty.
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) SetDefaultHook(hook func(context.Context, int) (core.Option[time.Time], error)) {
|
||||
// GetCommitAndDateForOldestUpload method of the parent MockStore instance
|
||||
// is invoked and the hook queue is empty.
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) SetDefaultHook(hook func(context.Context, int) (core.Option[store.CommitWithDate], error)) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
// PushHook adds a function to the end of hook queue. Each invocation of the
|
||||
// GetCommitDateForOldestUpload method of the parent MockStore instance
|
||||
// GetCommitAndDateForOldestUpload method of the parent MockStore instance
|
||||
// invokes the hook at the front of the queue and discards it. After the
|
||||
// queue is empty, the default hook function is invoked for any future
|
||||
// action.
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) PushHook(hook func(context.Context, int) (core.Option[time.Time], error)) {
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) PushHook(hook func(context.Context, int) (core.Option[store.CommitWithDate], error)) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
@ -2691,20 +2691,20 @@ func (f *StoreGetCommitDateForOldestUploadFunc) PushHook(hook func(context.Conte
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) SetDefaultReturn(r0 core.Option[time.Time], r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, int) (core.Option[time.Time], error) {
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) SetDefaultReturn(r0 core.Option[store.CommitWithDate], r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, int) (core.Option[store.CommitWithDate], error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) PushReturn(r0 core.Option[time.Time], r1 error) {
|
||||
f.PushHook(func(context.Context, int) (core.Option[time.Time], error) {
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) PushReturn(r0 core.Option[store.CommitWithDate], r1 error) {
|
||||
f.PushHook(func(context.Context, int) (core.Option[store.CommitWithDate], error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) nextHook() func(context.Context, int) (core.Option[time.Time], error) {
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) nextHook() func(context.Context, int) (core.Option[store.CommitWithDate], error) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
@ -2717,27 +2717,28 @@ func (f *StoreGetCommitDateForOldestUploadFunc) nextHook() func(context.Context,
|
||||
return hook
|
||||
}
|
||||
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) appendCall(r0 StoreGetCommitDateForOldestUploadFuncCall) {
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) appendCall(r0 StoreGetCommitAndDateForOldestUploadFuncCall) {
|
||||
f.mutex.Lock()
|
||||
f.history = append(f.history, r0)
|
||||
f.mutex.Unlock()
|
||||
}
|
||||
|
||||
// History returns a sequence of StoreGetCommitDateForOldestUploadFuncCall
|
||||
// objects describing the invocations of this function.
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) History() []StoreGetCommitDateForOldestUploadFuncCall {
|
||||
// History returns a sequence of
|
||||
// StoreGetCommitAndDateForOldestUploadFuncCall objects describing the
|
||||
// invocations of this function.
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) History() []StoreGetCommitAndDateForOldestUploadFuncCall {
|
||||
f.mutex.Lock()
|
||||
history := make([]StoreGetCommitDateForOldestUploadFuncCall, len(f.history))
|
||||
history := make([]StoreGetCommitAndDateForOldestUploadFuncCall, len(f.history))
|
||||
copy(history, f.history)
|
||||
f.mutex.Unlock()
|
||||
|
||||
return history
|
||||
}
|
||||
|
||||
// StoreGetCommitDateForOldestUploadFuncCall is an object that describes an
|
||||
// invocation of method GetCommitDateForOldestUpload on an instance of
|
||||
// StoreGetCommitAndDateForOldestUploadFuncCall is an object that describes
|
||||
// an invocation of method GetCommitAndDateForOldestUpload on an instance of
|
||||
// MockStore.
|
||||
type StoreGetCommitDateForOldestUploadFuncCall struct {
|
||||
type StoreGetCommitAndDateForOldestUploadFuncCall struct {
|
||||
// Arg0 is the value of the 1st argument passed to this method
|
||||
// invocation.
|
||||
Arg0 context.Context
|
||||
@ -2746,7 +2747,7 @@ type StoreGetCommitDateForOldestUploadFuncCall struct {
|
||||
Arg1 int
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 core.Option[time.Time]
|
||||
Result0 core.Option[store.CommitWithDate]
|
||||
// Result1 is the value of the 2nd result returned from this method
|
||||
// invocation.
|
||||
Result1 error
|
||||
@ -2754,13 +2755,13 @@ type StoreGetCommitDateForOldestUploadFuncCall struct {
|
||||
|
||||
// Args returns an interface slice containing the arguments of this
|
||||
// invocation.
|
||||
func (c StoreGetCommitDateForOldestUploadFuncCall) Args() []interface{} {
|
||||
func (c StoreGetCommitAndDateForOldestUploadFuncCall) Args() []interface{} {
|
||||
return []interface{}{c.Arg0, c.Arg1}
|
||||
}
|
||||
|
||||
// Results returns an interface slice containing the results of this
|
||||
// invocation.
|
||||
func (c StoreGetCommitDateForOldestUploadFuncCall) Results() []interface{} {
|
||||
func (c StoreGetCommitAndDateForOldestUploadFuncCall) Results() []interface{} {
|
||||
return []interface{}{c.Result0, c.Result1}
|
||||
}
|
||||
|
||||
|
||||
@ -15,11 +15,14 @@ go_library(
|
||||
"//internal/api",
|
||||
"//internal/codeintel/uploads/internal/commitgraph",
|
||||
"//internal/codeintel/uploads/internal/store",
|
||||
"//internal/conf",
|
||||
"//internal/database/locker",
|
||||
"//internal/env",
|
||||
"//internal/gitserver",
|
||||
"//internal/gitserver/gitdomain",
|
||||
"//internal/goroutine",
|
||||
"//lib/errors",
|
||||
"@com_github_grafana_regexp//:regexp",
|
||||
"@com_github_life4_genesis//slices",
|
||||
],
|
||||
)
|
||||
|
||||
@ -2,12 +2,17 @@ package commitgraph
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/regexp"
|
||||
genslices "github.com/life4/genesis/slices"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/actor"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/internal/commitgraph"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/internal/store"
|
||||
"github.com/sourcegraph/sourcegraph/internal/conf"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/locker"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
|
||||
@ -126,6 +131,13 @@ func mapRefsToCommits(refs []gitdomain.Ref) map[string][]gitdomain.Ref {
|
||||
return commitsByRef
|
||||
}
|
||||
|
||||
type CommitGraphRefreshStrategy string
|
||||
|
||||
const (
|
||||
HeadTopoOnly CommitGraphRefreshStrategy = "head-topo-only"
|
||||
AllRefsSince CommitGraphRefreshStrategy = "all-refs-since"
|
||||
)
|
||||
|
||||
// getCommitGraph builds a partial commit graph that includes the most recent commits on each branch
|
||||
// extending back as as the date of the oldest commit for which we have a processed upload for this
|
||||
// repository.
|
||||
@ -138,25 +150,53 @@ func mapRefsToCommits(refs []gitdomain.Ref) map[string][]gitdomain.Ref {
|
||||
// accelerating rate, as we routinely expire old information for active repositories in a janitor
|
||||
// process.
|
||||
func (s *commitGraphUpdater) getCommitGraph(ctx context.Context, repositoryID int, repo api.RepoName) (*commitgraph.CommitGraph, error) {
|
||||
optCommitDate, err := s.store.GetCommitDateForOldestUpload(ctx, repositoryID)
|
||||
optCommitWithDate, err := s.store.GetCommitAndDateForOldestUpload(ctx, repositoryID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if optCommitDate.IsNone() {
|
||||
commitWithDate, ok := optCommitWithDate.Get()
|
||||
if !ok {
|
||||
return commitgraph.ParseCommitGraph(nil), nil
|
||||
}
|
||||
commitDate := optCommitDate.Unwrap()
|
||||
|
||||
// The --since flag for git log is exclusive, but we want to include the commit where the
|
||||
// oldest dump is defined. This flag only has second resolution, so we shouldn't be pulling
|
||||
// back any more data than we wanted.
|
||||
commitDate = commitDate.Add(-time.Second)
|
||||
siteConfig := conf.SiteConfig()
|
||||
exptFeatures := siteConfig.ExperimentalFeatures
|
||||
var strat CommitGraphRefreshStrategy = AllRefsSince
|
||||
var defaultBranchRef string
|
||||
if exptFeatures != nil && exptFeatures.CommitGraphUpdates != nil {
|
||||
match := genslices.Any(exptFeatures.CommitGraphUpdates.DefaultBranchOnly, func(repoPattern string) bool {
|
||||
matched, err := regexp.MatchString(repoPattern, string(repo))
|
||||
return err == nil && matched
|
||||
})
|
||||
if match {
|
||||
if refName, _, err := s.gitserverClient.GetDefaultBranch(ctx, repo, false); err == nil {
|
||||
defaultBranchRef = refName
|
||||
strat = HeadTopoOnly
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
commits, err := s.gitserverClient.Commits(ctx, repo, gitserver.CommitsOptions{
|
||||
AllRefs: true,
|
||||
Order: gitserver.CommitsOrderTopoDate,
|
||||
After: commitDate,
|
||||
})
|
||||
var opts gitserver.CommitsOptions
|
||||
switch strat {
|
||||
case HeadTopoOnly:
|
||||
opts = gitserver.CommitsOptions{
|
||||
Ranges: []string{string(commitWithDate.Commit) + ".." + defaultBranchRef},
|
||||
Order: gitserver.CommitsOrderTopoDate,
|
||||
}
|
||||
case AllRefsSince:
|
||||
opts = gitserver.CommitsOptions{
|
||||
AllRefs: true,
|
||||
Order: gitserver.CommitsOrderTopoDate,
|
||||
// The --since flag for git log is exclusive, but we want to include the commit where the
|
||||
// oldest dump is defined. This flag only has second resolution, so we shouldn't be pulling
|
||||
// back any more data than we wanted.
|
||||
After: commitWithDate.CommitterDate.Add(-time.Second),
|
||||
}
|
||||
default:
|
||||
panic(fmt.Sprintf("Unhandled case for strategy: %q", strat))
|
||||
}
|
||||
|
||||
commits, err := s.gitserverClient.Commits(ctx, repo, opts)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "gitserver.Commits")
|
||||
}
|
||||
|
||||
@ -419,10 +419,10 @@ type MockStore struct {
|
||||
// GetAuditLogsForUploadFunc is an instance of a mock function object
|
||||
// controlling the behavior of the method GetAuditLogsForUpload.
|
||||
GetAuditLogsForUploadFunc *StoreGetAuditLogsForUploadFunc
|
||||
// GetCommitDateForOldestUploadFunc is an instance of a mock function
|
||||
// GetCommitAndDateForOldestUploadFunc is an instance of a mock function
|
||||
// object controlling the behavior of the method
|
||||
// GetCommitDateForOldestUpload.
|
||||
GetCommitDateForOldestUploadFunc *StoreGetCommitDateForOldestUploadFunc
|
||||
// GetCommitAndDateForOldestUpload.
|
||||
GetCommitAndDateForOldestUploadFunc *StoreGetCommitAndDateForOldestUploadFunc
|
||||
// GetCommitGraphMetadataFunc is an instance of a mock function object
|
||||
// controlling the behavior of the method GetCommitGraphMetadata.
|
||||
GetCommitGraphMetadataFunc *StoreGetCommitGraphMetadataFunc
|
||||
@ -660,8 +660,8 @@ func NewMockStore() *MockStore {
|
||||
return
|
||||
},
|
||||
},
|
||||
GetCommitDateForOldestUploadFunc: &StoreGetCommitDateForOldestUploadFunc{
|
||||
defaultHook: func(context.Context, int) (r0 core.Option[time.Time], r1 error) {
|
||||
GetCommitAndDateForOldestUploadFunc: &StoreGetCommitAndDateForOldestUploadFunc{
|
||||
defaultHook: func(context.Context, int) (r0 core.Option[store.CommitWithDate], r1 error) {
|
||||
return
|
||||
},
|
||||
},
|
||||
@ -987,9 +987,9 @@ func NewStrictMockStore() *MockStore {
|
||||
panic("unexpected invocation of MockStore.GetAuditLogsForUpload")
|
||||
},
|
||||
},
|
||||
GetCommitDateForOldestUploadFunc: &StoreGetCommitDateForOldestUploadFunc{
|
||||
defaultHook: func(context.Context, int) (core.Option[time.Time], error) {
|
||||
panic("unexpected invocation of MockStore.GetCommitDateForOldestUpload")
|
||||
GetCommitAndDateForOldestUploadFunc: &StoreGetCommitAndDateForOldestUploadFunc{
|
||||
defaultHook: func(context.Context, int) (core.Option[store.CommitWithDate], error) {
|
||||
panic("unexpected invocation of MockStore.GetCommitAndDateForOldestUpload")
|
||||
},
|
||||
},
|
||||
GetCommitGraphMetadataFunc: &StoreGetCommitGraphMetadataFunc{
|
||||
@ -1286,8 +1286,8 @@ func NewMockStoreFrom(i store.Store) *MockStore {
|
||||
GetAuditLogsForUploadFunc: &StoreGetAuditLogsForUploadFunc{
|
||||
defaultHook: i.GetAuditLogsForUpload,
|
||||
},
|
||||
GetCommitDateForOldestUploadFunc: &StoreGetCommitDateForOldestUploadFunc{
|
||||
defaultHook: i.GetCommitDateForOldestUpload,
|
||||
GetCommitAndDateForOldestUploadFunc: &StoreGetCommitAndDateForOldestUploadFunc{
|
||||
defaultHook: i.GetCommitAndDateForOldestUpload,
|
||||
},
|
||||
GetCommitGraphMetadataFunc: &StoreGetCommitGraphMetadataFunc{
|
||||
defaultHook: i.GetCommitGraphMetadata,
|
||||
@ -2996,37 +2996,37 @@ func (c StoreGetAuditLogsForUploadFuncCall) Results() []interface{} {
|
||||
return []interface{}{c.Result0, c.Result1}
|
||||
}
|
||||
|
||||
// StoreGetCommitDateForOldestUploadFunc describes the behavior when the
|
||||
// GetCommitDateForOldestUpload method of the parent MockStore instance is
|
||||
// invoked.
|
||||
type StoreGetCommitDateForOldestUploadFunc struct {
|
||||
defaultHook func(context.Context, int) (core.Option[time.Time], error)
|
||||
hooks []func(context.Context, int) (core.Option[time.Time], error)
|
||||
history []StoreGetCommitDateForOldestUploadFuncCall
|
||||
// StoreGetCommitAndDateForOldestUploadFunc describes the behavior when the
|
||||
// GetCommitAndDateForOldestUpload method of the parent MockStore instance
|
||||
// is invoked.
|
||||
type StoreGetCommitAndDateForOldestUploadFunc struct {
|
||||
defaultHook func(context.Context, int) (core.Option[store.CommitWithDate], error)
|
||||
hooks []func(context.Context, int) (core.Option[store.CommitWithDate], error)
|
||||
history []StoreGetCommitAndDateForOldestUploadFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// GetCommitDateForOldestUpload delegates to the next hook function in the
|
||||
// queue and stores the parameter and result values of this invocation.
|
||||
func (m *MockStore) GetCommitDateForOldestUpload(v0 context.Context, v1 int) (core.Option[time.Time], error) {
|
||||
r0, r1 := m.GetCommitDateForOldestUploadFunc.nextHook()(v0, v1)
|
||||
m.GetCommitDateForOldestUploadFunc.appendCall(StoreGetCommitDateForOldestUploadFuncCall{v0, v1, r0, r1})
|
||||
// GetCommitAndDateForOldestUpload delegates to the next hook function in
|
||||
// the queue and stores the parameter and result values of this invocation.
|
||||
func (m *MockStore) GetCommitAndDateForOldestUpload(v0 context.Context, v1 int) (core.Option[store.CommitWithDate], error) {
|
||||
r0, r1 := m.GetCommitAndDateForOldestUploadFunc.nextHook()(v0, v1)
|
||||
m.GetCommitAndDateForOldestUploadFunc.appendCall(StoreGetCommitAndDateForOldestUploadFuncCall{v0, v1, r0, r1})
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// SetDefaultHook sets function that is called when the
|
||||
// GetCommitDateForOldestUpload method of the parent MockStore instance is
|
||||
// invoked and the hook queue is empty.
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) SetDefaultHook(hook func(context.Context, int) (core.Option[time.Time], error)) {
|
||||
// GetCommitAndDateForOldestUpload method of the parent MockStore instance
|
||||
// is invoked and the hook queue is empty.
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) SetDefaultHook(hook func(context.Context, int) (core.Option[store.CommitWithDate], error)) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
// PushHook adds a function to the end of hook queue. Each invocation of the
|
||||
// GetCommitDateForOldestUpload method of the parent MockStore instance
|
||||
// GetCommitAndDateForOldestUpload method of the parent MockStore instance
|
||||
// invokes the hook at the front of the queue and discards it. After the
|
||||
// queue is empty, the default hook function is invoked for any future
|
||||
// action.
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) PushHook(hook func(context.Context, int) (core.Option[time.Time], error)) {
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) PushHook(hook func(context.Context, int) (core.Option[store.CommitWithDate], error)) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
@ -3034,20 +3034,20 @@ func (f *StoreGetCommitDateForOldestUploadFunc) PushHook(hook func(context.Conte
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) SetDefaultReturn(r0 core.Option[time.Time], r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, int) (core.Option[time.Time], error) {
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) SetDefaultReturn(r0 core.Option[store.CommitWithDate], r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, int) (core.Option[store.CommitWithDate], error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) PushReturn(r0 core.Option[time.Time], r1 error) {
|
||||
f.PushHook(func(context.Context, int) (core.Option[time.Time], error) {
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) PushReturn(r0 core.Option[store.CommitWithDate], r1 error) {
|
||||
f.PushHook(func(context.Context, int) (core.Option[store.CommitWithDate], error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) nextHook() func(context.Context, int) (core.Option[time.Time], error) {
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) nextHook() func(context.Context, int) (core.Option[store.CommitWithDate], error) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
@ -3060,27 +3060,28 @@ func (f *StoreGetCommitDateForOldestUploadFunc) nextHook() func(context.Context,
|
||||
return hook
|
||||
}
|
||||
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) appendCall(r0 StoreGetCommitDateForOldestUploadFuncCall) {
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) appendCall(r0 StoreGetCommitAndDateForOldestUploadFuncCall) {
|
||||
f.mutex.Lock()
|
||||
f.history = append(f.history, r0)
|
||||
f.mutex.Unlock()
|
||||
}
|
||||
|
||||
// History returns a sequence of StoreGetCommitDateForOldestUploadFuncCall
|
||||
// objects describing the invocations of this function.
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) History() []StoreGetCommitDateForOldestUploadFuncCall {
|
||||
// History returns a sequence of
|
||||
// StoreGetCommitAndDateForOldestUploadFuncCall objects describing the
|
||||
// invocations of this function.
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) History() []StoreGetCommitAndDateForOldestUploadFuncCall {
|
||||
f.mutex.Lock()
|
||||
history := make([]StoreGetCommitDateForOldestUploadFuncCall, len(f.history))
|
||||
history := make([]StoreGetCommitAndDateForOldestUploadFuncCall, len(f.history))
|
||||
copy(history, f.history)
|
||||
f.mutex.Unlock()
|
||||
|
||||
return history
|
||||
}
|
||||
|
||||
// StoreGetCommitDateForOldestUploadFuncCall is an object that describes an
|
||||
// invocation of method GetCommitDateForOldestUpload on an instance of
|
||||
// StoreGetCommitAndDateForOldestUploadFuncCall is an object that describes
|
||||
// an invocation of method GetCommitAndDateForOldestUpload on an instance of
|
||||
// MockStore.
|
||||
type StoreGetCommitDateForOldestUploadFuncCall struct {
|
||||
type StoreGetCommitAndDateForOldestUploadFuncCall struct {
|
||||
// Arg0 is the value of the 1st argument passed to this method
|
||||
// invocation.
|
||||
Arg0 context.Context
|
||||
@ -3089,7 +3090,7 @@ type StoreGetCommitDateForOldestUploadFuncCall struct {
|
||||
Arg1 int
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 core.Option[time.Time]
|
||||
Result0 core.Option[store.CommitWithDate]
|
||||
// Result1 is the value of the 2nd result returned from this method
|
||||
// invocation.
|
||||
Result1 error
|
||||
@ -3097,13 +3098,13 @@ type StoreGetCommitDateForOldestUploadFuncCall struct {
|
||||
|
||||
// Args returns an interface slice containing the arguments of this
|
||||
// invocation.
|
||||
func (c StoreGetCommitDateForOldestUploadFuncCall) Args() []interface{} {
|
||||
func (c StoreGetCommitAndDateForOldestUploadFuncCall) Args() []interface{} {
|
||||
return []interface{}{c.Arg0, c.Arg1}
|
||||
}
|
||||
|
||||
// Results returns an interface slice containing the results of this
|
||||
// invocation.
|
||||
func (c StoreGetCommitDateForOldestUploadFuncCall) Results() []interface{} {
|
||||
func (c StoreGetCommitAndDateForOldestUploadFuncCall) Results() []interface{} {
|
||||
return []interface{}{c.Result0, c.Result1}
|
||||
}
|
||||
|
||||
|
||||
@ -233,10 +233,10 @@ type MockStore struct {
|
||||
// GetAuditLogsForUploadFunc is an instance of a mock function object
|
||||
// controlling the behavior of the method GetAuditLogsForUpload.
|
||||
GetAuditLogsForUploadFunc *StoreGetAuditLogsForUploadFunc
|
||||
// GetCommitDateForOldestUploadFunc is an instance of a mock function
|
||||
// GetCommitAndDateForOldestUploadFunc is an instance of a mock function
|
||||
// object controlling the behavior of the method
|
||||
// GetCommitDateForOldestUpload.
|
||||
GetCommitDateForOldestUploadFunc *StoreGetCommitDateForOldestUploadFunc
|
||||
// GetCommitAndDateForOldestUpload.
|
||||
GetCommitAndDateForOldestUploadFunc *StoreGetCommitAndDateForOldestUploadFunc
|
||||
// GetCommitGraphMetadataFunc is an instance of a mock function object
|
||||
// controlling the behavior of the method GetCommitGraphMetadata.
|
||||
GetCommitGraphMetadataFunc *StoreGetCommitGraphMetadataFunc
|
||||
@ -474,8 +474,8 @@ func NewMockStore() *MockStore {
|
||||
return
|
||||
},
|
||||
},
|
||||
GetCommitDateForOldestUploadFunc: &StoreGetCommitDateForOldestUploadFunc{
|
||||
defaultHook: func(context.Context, int) (r0 core.Option[time.Time], r1 error) {
|
||||
GetCommitAndDateForOldestUploadFunc: &StoreGetCommitAndDateForOldestUploadFunc{
|
||||
defaultHook: func(context.Context, int) (r0 core.Option[store.CommitWithDate], r1 error) {
|
||||
return
|
||||
},
|
||||
},
|
||||
@ -801,9 +801,9 @@ func NewStrictMockStore() *MockStore {
|
||||
panic("unexpected invocation of MockStore.GetAuditLogsForUpload")
|
||||
},
|
||||
},
|
||||
GetCommitDateForOldestUploadFunc: &StoreGetCommitDateForOldestUploadFunc{
|
||||
defaultHook: func(context.Context, int) (core.Option[time.Time], error) {
|
||||
panic("unexpected invocation of MockStore.GetCommitDateForOldestUpload")
|
||||
GetCommitAndDateForOldestUploadFunc: &StoreGetCommitAndDateForOldestUploadFunc{
|
||||
defaultHook: func(context.Context, int) (core.Option[store.CommitWithDate], error) {
|
||||
panic("unexpected invocation of MockStore.GetCommitAndDateForOldestUpload")
|
||||
},
|
||||
},
|
||||
GetCommitGraphMetadataFunc: &StoreGetCommitGraphMetadataFunc{
|
||||
@ -1100,8 +1100,8 @@ func NewMockStoreFrom(i store.Store) *MockStore {
|
||||
GetAuditLogsForUploadFunc: &StoreGetAuditLogsForUploadFunc{
|
||||
defaultHook: i.GetAuditLogsForUpload,
|
||||
},
|
||||
GetCommitDateForOldestUploadFunc: &StoreGetCommitDateForOldestUploadFunc{
|
||||
defaultHook: i.GetCommitDateForOldestUpload,
|
||||
GetCommitAndDateForOldestUploadFunc: &StoreGetCommitAndDateForOldestUploadFunc{
|
||||
defaultHook: i.GetCommitAndDateForOldestUpload,
|
||||
},
|
||||
GetCommitGraphMetadataFunc: &StoreGetCommitGraphMetadataFunc{
|
||||
defaultHook: i.GetCommitGraphMetadata,
|
||||
@ -2810,37 +2810,37 @@ func (c StoreGetAuditLogsForUploadFuncCall) Results() []interface{} {
|
||||
return []interface{}{c.Result0, c.Result1}
|
||||
}
|
||||
|
||||
// StoreGetCommitDateForOldestUploadFunc describes the behavior when the
|
||||
// GetCommitDateForOldestUpload method of the parent MockStore instance is
|
||||
// invoked.
|
||||
type StoreGetCommitDateForOldestUploadFunc struct {
|
||||
defaultHook func(context.Context, int) (core.Option[time.Time], error)
|
||||
hooks []func(context.Context, int) (core.Option[time.Time], error)
|
||||
history []StoreGetCommitDateForOldestUploadFuncCall
|
||||
// StoreGetCommitAndDateForOldestUploadFunc describes the behavior when the
|
||||
// GetCommitAndDateForOldestUpload method of the parent MockStore instance
|
||||
// is invoked.
|
||||
type StoreGetCommitAndDateForOldestUploadFunc struct {
|
||||
defaultHook func(context.Context, int) (core.Option[store.CommitWithDate], error)
|
||||
hooks []func(context.Context, int) (core.Option[store.CommitWithDate], error)
|
||||
history []StoreGetCommitAndDateForOldestUploadFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// GetCommitDateForOldestUpload delegates to the next hook function in the
|
||||
// queue and stores the parameter and result values of this invocation.
|
||||
func (m *MockStore) GetCommitDateForOldestUpload(v0 context.Context, v1 int) (core.Option[time.Time], error) {
|
||||
r0, r1 := m.GetCommitDateForOldestUploadFunc.nextHook()(v0, v1)
|
||||
m.GetCommitDateForOldestUploadFunc.appendCall(StoreGetCommitDateForOldestUploadFuncCall{v0, v1, r0, r1})
|
||||
// GetCommitAndDateForOldestUpload delegates to the next hook function in
|
||||
// the queue and stores the parameter and result values of this invocation.
|
||||
func (m *MockStore) GetCommitAndDateForOldestUpload(v0 context.Context, v1 int) (core.Option[store.CommitWithDate], error) {
|
||||
r0, r1 := m.GetCommitAndDateForOldestUploadFunc.nextHook()(v0, v1)
|
||||
m.GetCommitAndDateForOldestUploadFunc.appendCall(StoreGetCommitAndDateForOldestUploadFuncCall{v0, v1, r0, r1})
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// SetDefaultHook sets function that is called when the
|
||||
// GetCommitDateForOldestUpload method of the parent MockStore instance is
|
||||
// invoked and the hook queue is empty.
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) SetDefaultHook(hook func(context.Context, int) (core.Option[time.Time], error)) {
|
||||
// GetCommitAndDateForOldestUpload method of the parent MockStore instance
|
||||
// is invoked and the hook queue is empty.
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) SetDefaultHook(hook func(context.Context, int) (core.Option[store.CommitWithDate], error)) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
// PushHook adds a function to the end of hook queue. Each invocation of the
|
||||
// GetCommitDateForOldestUpload method of the parent MockStore instance
|
||||
// GetCommitAndDateForOldestUpload method of the parent MockStore instance
|
||||
// invokes the hook at the front of the queue and discards it. After the
|
||||
// queue is empty, the default hook function is invoked for any future
|
||||
// action.
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) PushHook(hook func(context.Context, int) (core.Option[time.Time], error)) {
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) PushHook(hook func(context.Context, int) (core.Option[store.CommitWithDate], error)) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
@ -2848,20 +2848,20 @@ func (f *StoreGetCommitDateForOldestUploadFunc) PushHook(hook func(context.Conte
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) SetDefaultReturn(r0 core.Option[time.Time], r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, int) (core.Option[time.Time], error) {
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) SetDefaultReturn(r0 core.Option[store.CommitWithDate], r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, int) (core.Option[store.CommitWithDate], error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) PushReturn(r0 core.Option[time.Time], r1 error) {
|
||||
f.PushHook(func(context.Context, int) (core.Option[time.Time], error) {
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) PushReturn(r0 core.Option[store.CommitWithDate], r1 error) {
|
||||
f.PushHook(func(context.Context, int) (core.Option[store.CommitWithDate], error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) nextHook() func(context.Context, int) (core.Option[time.Time], error) {
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) nextHook() func(context.Context, int) (core.Option[store.CommitWithDate], error) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
@ -2874,27 +2874,28 @@ func (f *StoreGetCommitDateForOldestUploadFunc) nextHook() func(context.Context,
|
||||
return hook
|
||||
}
|
||||
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) appendCall(r0 StoreGetCommitDateForOldestUploadFuncCall) {
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) appendCall(r0 StoreGetCommitAndDateForOldestUploadFuncCall) {
|
||||
f.mutex.Lock()
|
||||
f.history = append(f.history, r0)
|
||||
f.mutex.Unlock()
|
||||
}
|
||||
|
||||
// History returns a sequence of StoreGetCommitDateForOldestUploadFuncCall
|
||||
// objects describing the invocations of this function.
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) History() []StoreGetCommitDateForOldestUploadFuncCall {
|
||||
// History returns a sequence of
|
||||
// StoreGetCommitAndDateForOldestUploadFuncCall objects describing the
|
||||
// invocations of this function.
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) History() []StoreGetCommitAndDateForOldestUploadFuncCall {
|
||||
f.mutex.Lock()
|
||||
history := make([]StoreGetCommitDateForOldestUploadFuncCall, len(f.history))
|
||||
history := make([]StoreGetCommitAndDateForOldestUploadFuncCall, len(f.history))
|
||||
copy(history, f.history)
|
||||
f.mutex.Unlock()
|
||||
|
||||
return history
|
||||
}
|
||||
|
||||
// StoreGetCommitDateForOldestUploadFuncCall is an object that describes an
|
||||
// invocation of method GetCommitDateForOldestUpload on an instance of
|
||||
// StoreGetCommitAndDateForOldestUploadFuncCall is an object that describes
|
||||
// an invocation of method GetCommitAndDateForOldestUpload on an instance of
|
||||
// MockStore.
|
||||
type StoreGetCommitDateForOldestUploadFuncCall struct {
|
||||
type StoreGetCommitAndDateForOldestUploadFuncCall struct {
|
||||
// Arg0 is the value of the 1st argument passed to this method
|
||||
// invocation.
|
||||
Arg0 context.Context
|
||||
@ -2903,7 +2904,7 @@ type StoreGetCommitDateForOldestUploadFuncCall struct {
|
||||
Arg1 int
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 core.Option[time.Time]
|
||||
Result0 core.Option[store.CommitWithDate]
|
||||
// Result1 is the value of the 2nd result returned from this method
|
||||
// invocation.
|
||||
Result1 error
|
||||
@ -2911,13 +2912,13 @@ type StoreGetCommitDateForOldestUploadFuncCall struct {
|
||||
|
||||
// Args returns an interface slice containing the arguments of this
|
||||
// invocation.
|
||||
func (c StoreGetCommitDateForOldestUploadFuncCall) Args() []interface{} {
|
||||
func (c StoreGetCommitAndDateForOldestUploadFuncCall) Args() []interface{} {
|
||||
return []interface{}{c.Arg0, c.Arg1}
|
||||
}
|
||||
|
||||
// Results returns an interface slice containing the results of this
|
||||
// invocation.
|
||||
func (c StoreGetCommitDateForOldestUploadFuncCall) Results() []interface{} {
|
||||
func (c StoreGetCommitAndDateForOldestUploadFuncCall) Results() []interface{} {
|
||||
return []interface{}{c.Result0, c.Result1}
|
||||
}
|
||||
|
||||
|
||||
@ -93,5 +93,6 @@ go_test(
|
||||
"@com_github_lib_pq//:pq",
|
||||
"@com_github_sourcegraph_log//:log",
|
||||
"@com_github_sourcegraph_log//logtest",
|
||||
"@com_github_stretchr_testify//require",
|
||||
],
|
||||
)
|
||||
|
||||
@ -8,40 +8,56 @@ import (
|
||||
"github.com/keegancsmith/sqlf"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/core"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/basestore"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/dbutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
)
|
||||
|
||||
type CommitWithDate struct {
|
||||
Commit api.CommitID
|
||||
CommitterDate time.Time
|
||||
}
|
||||
|
||||
// GetCommitDateForOldestUpload returns the oldest commit date for all uploads for the given repository.
|
||||
// - If there are any null values, the commit date backfill job has not yet completed and
|
||||
// an error is returned to prevent downstream expiration errors being made due to outdated commit graph data.
|
||||
// - Otherwise if there are no non-nil timestamps, None is returned.
|
||||
func (s *store) GetCommitDateForOldestUpload(ctx context.Context, repositoryID int) (_ core.Option[time.Time], err error) {
|
||||
ctx, _, endObservation := s.operations.getCommitDateForOldestUpload.With(ctx, &err, observation.Args{Attrs: []attribute.KeyValue{
|
||||
// - Otherwise if there are no non-nil timestamps, Some is returned.
|
||||
func (s *store) GetCommitAndDateForOldestUpload(ctx context.Context, repositoryID int) (_ core.Option[CommitWithDate], err error) {
|
||||
ctx, _, endObservation := s.operations.getCommitAndDateForOldestUpload.With(ctx, &err, observation.Args{Attrs: []attribute.KeyValue{
|
||||
attribute.Int("repositoryID", repositoryID),
|
||||
}})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
var none = core.None[time.Time]()
|
||||
t, ok, err := basestore.ScanFirstNullTime(s.db.Query(ctx, sqlf.Sprintf(getCommitDateForOldestUploadQuery, repositoryID)))
|
||||
var none = core.None[CommitWithDate]()
|
||||
type commitWithNullDate struct {
|
||||
commit string
|
||||
t *time.Time
|
||||
}
|
||||
data, ok, err := basestore.NewFirstScanner(func(scanner dbutil.Scanner) (commitWithNullDate, error) {
|
||||
var commit string
|
||||
var t *time.Time
|
||||
err := scanner.Scan(&commit, &t)
|
||||
return commitWithNullDate{commit, t}, err
|
||||
})(s.db.Query(ctx, sqlf.Sprintf(getCommitAndDateForOldestUploadQuery, repositoryID)))
|
||||
|
||||
if err != nil || !ok {
|
||||
return none, err
|
||||
}
|
||||
if t == nil {
|
||||
if data.t == nil {
|
||||
return none, &backfillIncompleteError{repositoryID}
|
||||
}
|
||||
|
||||
return core.Some(*t), nil
|
||||
return core.Some(CommitWithDate{Commit: api.CommitID(data.commit), CommitterDate: *data.t}), nil
|
||||
}
|
||||
|
||||
// Note: we check against '-infinity' here, as the backfill operation will use this sentinel value in the case
|
||||
// that the commit is no longer know by gitserver. This allows the backfill migration to make progress without
|
||||
// having pristine database.
|
||||
const getCommitDateForOldestUploadQuery = `
|
||||
const getCommitAndDateForOldestUploadQuery = `
|
||||
SELECT
|
||||
cd.committed_at
|
||||
u.commit, cd.committed_at
|
||||
FROM lsif_uploads u
|
||||
LEFT JOIN codeintel_commit_dates cd ON cd.repository_id = u.repository_id AND cd.commit_bytea = decode(u.commit, 'hex')
|
||||
WHERE
|
||||
|
||||
@ -7,7 +7,9 @@ import (
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/sourcegraph/log/logtest"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/dbtest"
|
||||
@ -53,7 +55,7 @@ func TestGetOldestCommitDate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := store.GetCommitDateForOldestUpload(context.Background(), 50); err == nil {
|
||||
if _, err := store.GetCommitAndDateForOldestUpload(context.Background(), 50); err == nil {
|
||||
t.Fatalf("expected error getting oldest commit date")
|
||||
} else if !errors.Is(err, &backfillIncompleteError{50}) {
|
||||
t.Fatalf("unexpected backfill error, got %q", err)
|
||||
@ -64,12 +66,12 @@ func TestGetOldestCommitDate(t *testing.T) {
|
||||
t.Fatalf("unexpected error updating commit date %s", err)
|
||||
}
|
||||
|
||||
if commitDate, err := store.GetCommitDateForOldestUpload(context.Background(), 50); err != nil {
|
||||
if commitWithDate, err := store.GetCommitAndDateForOldestUpload(context.Background(), 50); err != nil {
|
||||
t.Fatalf("unexpected error getting oldest commit date: %s", err)
|
||||
} else if commitDate.IsNone() {
|
||||
} else if commitWithDate.IsNone() {
|
||||
t.Fatalf("expected commit date for repository")
|
||||
} else if !commitDate.Unwrap().Equal(t3) {
|
||||
t.Fatalf("unexpected commit date. want=%s have=%s", t3, commitDate)
|
||||
} else {
|
||||
require.Equal(t, CommitWithDate{Commit: api.CommitID(makeCommit(1)), CommitterDate: t3}, commitWithDate.Unwrap())
|
||||
}
|
||||
|
||||
// Repo 51
|
||||
@ -83,16 +85,16 @@ func TestGetOldestCommitDate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
if commitDate, err := store.GetCommitDateForOldestUpload(context.Background(), 51); err != nil {
|
||||
if commitAndDate, err := store.GetCommitAndDateForOldestUpload(context.Background(), 51); err != nil {
|
||||
t.Fatalf("unexpected error getting oldest commit date: %s", err)
|
||||
} else if commitDate.IsNone() {
|
||||
} else if commitAndDate.IsNone() {
|
||||
t.Fatalf("expected commit date for repository")
|
||||
} else if !commitDate.Unwrap().Equal(t2) {
|
||||
t.Fatalf("unexpected commit date. want=%s have=%s", t2, commitDate)
|
||||
} else {
|
||||
require.Equal(t, CommitWithDate{Commit: api.CommitID(makeCommit(6)), CommitterDate: t2}, commitAndDate.Unwrap())
|
||||
}
|
||||
|
||||
// Missing repository
|
||||
if commitDate, err := store.GetCommitDateForOldestUpload(context.Background(), 52); err != nil {
|
||||
if commitDate, err := store.GetCommitAndDateForOldestUpload(context.Background(), 52); err != nil {
|
||||
t.Fatalf("unexpected error getting oldest commit date: %s", err)
|
||||
} else if commitDate.IsSome() {
|
||||
t.Fatalf("unexpected commit date for repository")
|
||||
|
||||
@ -16,7 +16,7 @@ type operations struct {
|
||||
deleteSourcedCommits *observation.Operation
|
||||
updateSourcedCommits *observation.Operation
|
||||
getCommitsVisibleToUpload *observation.Operation
|
||||
getCommitDateForOldestUpload *observation.Operation
|
||||
getCommitAndDateForOldestUpload *observation.Operation
|
||||
getCommitGraphMetadata *observation.Operation
|
||||
hasCommit *observation.Operation
|
||||
repositoryIDsWithErrors *observation.Operation
|
||||
@ -121,13 +121,13 @@ func newOperations(observationCtx *observation.Context) *operations {
|
||||
list: op("List"),
|
||||
|
||||
// Commits
|
||||
getCommitsVisibleToUpload: op("CommitsVisibleToUploads"),
|
||||
getCommitDateForOldestUpload: op("GetCommitDateForOldestUpload"),
|
||||
getStaleSourcedCommits: op("GetStaleSourcedCommits"),
|
||||
getCommitGraphMetadata: op("GetCommitGraphMetadata"),
|
||||
deleteSourcedCommits: op("DeleteSourcedCommits"),
|
||||
updateSourcedCommits: op("UpdateSourcedCommits"),
|
||||
hasCommit: op("HasCommit"),
|
||||
getCommitsVisibleToUpload: op("CommitsVisibleToUploads"),
|
||||
getCommitAndDateForOldestUpload: op("GetCommitAndDateForOldestUpload"),
|
||||
getStaleSourcedCommits: op("GetStaleSourcedCommits"),
|
||||
getCommitGraphMetadata: op("GetCommitGraphMetadata"),
|
||||
deleteSourcedCommits: op("DeleteSourcedCommits"),
|
||||
updateSourcedCommits: op("UpdateSourcedCommits"),
|
||||
hasCommit: op("HasCommit"),
|
||||
|
||||
// Repositories
|
||||
getRepositoriesForIndexScan: op("GetRepositoriesForIndexScan"),
|
||||
|
||||
@ -88,7 +88,7 @@ type Store interface {
|
||||
SoftDeleteExpiredUploadsViaTraversal(ctx context.Context, maxTraversal int) (int, int, error)
|
||||
|
||||
// Commit date
|
||||
GetCommitDateForOldestUpload(ctx context.Context, repositoryID int) (core.Option[time.Time], error)
|
||||
GetCommitAndDateForOldestUpload(ctx context.Context, repositoryID int) (core.Option[CommitWithDate], error)
|
||||
UpdateCommittedAt(ctx context.Context, repositoryID int, commit, commitDateString string) error
|
||||
SourcedCommitsWithoutCommittedAt(ctx context.Context, batchSize int) ([]SourcedCommits, error)
|
||||
|
||||
|
||||
87
internal/codeintel/uploads/mocks_test.go
generated
87
internal/codeintel/uploads/mocks_test.go
generated
@ -82,10 +82,10 @@ type MockStore struct {
|
||||
// GetAuditLogsForUploadFunc is an instance of a mock function object
|
||||
// controlling the behavior of the method GetAuditLogsForUpload.
|
||||
GetAuditLogsForUploadFunc *StoreGetAuditLogsForUploadFunc
|
||||
// GetCommitDateForOldestUploadFunc is an instance of a mock function
|
||||
// GetCommitAndDateForOldestUploadFunc is an instance of a mock function
|
||||
// object controlling the behavior of the method
|
||||
// GetCommitDateForOldestUpload.
|
||||
GetCommitDateForOldestUploadFunc *StoreGetCommitDateForOldestUploadFunc
|
||||
// GetCommitAndDateForOldestUpload.
|
||||
GetCommitAndDateForOldestUploadFunc *StoreGetCommitAndDateForOldestUploadFunc
|
||||
// GetCommitGraphMetadataFunc is an instance of a mock function object
|
||||
// controlling the behavior of the method GetCommitGraphMetadata.
|
||||
GetCommitGraphMetadataFunc *StoreGetCommitGraphMetadataFunc
|
||||
@ -323,8 +323,8 @@ func NewMockStore() *MockStore {
|
||||
return
|
||||
},
|
||||
},
|
||||
GetCommitDateForOldestUploadFunc: &StoreGetCommitDateForOldestUploadFunc{
|
||||
defaultHook: func(context.Context, int) (r0 core.Option[time.Time], r1 error) {
|
||||
GetCommitAndDateForOldestUploadFunc: &StoreGetCommitAndDateForOldestUploadFunc{
|
||||
defaultHook: func(context.Context, int) (r0 core.Option[store.CommitWithDate], r1 error) {
|
||||
return
|
||||
},
|
||||
},
|
||||
@ -650,9 +650,9 @@ func NewStrictMockStore() *MockStore {
|
||||
panic("unexpected invocation of MockStore.GetAuditLogsForUpload")
|
||||
},
|
||||
},
|
||||
GetCommitDateForOldestUploadFunc: &StoreGetCommitDateForOldestUploadFunc{
|
||||
defaultHook: func(context.Context, int) (core.Option[time.Time], error) {
|
||||
panic("unexpected invocation of MockStore.GetCommitDateForOldestUpload")
|
||||
GetCommitAndDateForOldestUploadFunc: &StoreGetCommitAndDateForOldestUploadFunc{
|
||||
defaultHook: func(context.Context, int) (core.Option[store.CommitWithDate], error) {
|
||||
panic("unexpected invocation of MockStore.GetCommitAndDateForOldestUpload")
|
||||
},
|
||||
},
|
||||
GetCommitGraphMetadataFunc: &StoreGetCommitGraphMetadataFunc{
|
||||
@ -949,8 +949,8 @@ func NewMockStoreFrom(i store.Store) *MockStore {
|
||||
GetAuditLogsForUploadFunc: &StoreGetAuditLogsForUploadFunc{
|
||||
defaultHook: i.GetAuditLogsForUpload,
|
||||
},
|
||||
GetCommitDateForOldestUploadFunc: &StoreGetCommitDateForOldestUploadFunc{
|
||||
defaultHook: i.GetCommitDateForOldestUpload,
|
||||
GetCommitAndDateForOldestUploadFunc: &StoreGetCommitAndDateForOldestUploadFunc{
|
||||
defaultHook: i.GetCommitAndDateForOldestUpload,
|
||||
},
|
||||
GetCommitGraphMetadataFunc: &StoreGetCommitGraphMetadataFunc{
|
||||
defaultHook: i.GetCommitGraphMetadata,
|
||||
@ -2659,37 +2659,37 @@ func (c StoreGetAuditLogsForUploadFuncCall) Results() []interface{} {
|
||||
return []interface{}{c.Result0, c.Result1}
|
||||
}
|
||||
|
||||
// StoreGetCommitDateForOldestUploadFunc describes the behavior when the
|
||||
// GetCommitDateForOldestUpload method of the parent MockStore instance is
|
||||
// invoked.
|
||||
type StoreGetCommitDateForOldestUploadFunc struct {
|
||||
defaultHook func(context.Context, int) (core.Option[time.Time], error)
|
||||
hooks []func(context.Context, int) (core.Option[time.Time], error)
|
||||
history []StoreGetCommitDateForOldestUploadFuncCall
|
||||
// StoreGetCommitAndDateForOldestUploadFunc describes the behavior when the
|
||||
// GetCommitAndDateForOldestUpload method of the parent MockStore instance
|
||||
// is invoked.
|
||||
type StoreGetCommitAndDateForOldestUploadFunc struct {
|
||||
defaultHook func(context.Context, int) (core.Option[store.CommitWithDate], error)
|
||||
hooks []func(context.Context, int) (core.Option[store.CommitWithDate], error)
|
||||
history []StoreGetCommitAndDateForOldestUploadFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// GetCommitDateForOldestUpload delegates to the next hook function in the
|
||||
// queue and stores the parameter and result values of this invocation.
|
||||
func (m *MockStore) GetCommitDateForOldestUpload(v0 context.Context, v1 int) (core.Option[time.Time], error) {
|
||||
r0, r1 := m.GetCommitDateForOldestUploadFunc.nextHook()(v0, v1)
|
||||
m.GetCommitDateForOldestUploadFunc.appendCall(StoreGetCommitDateForOldestUploadFuncCall{v0, v1, r0, r1})
|
||||
// GetCommitAndDateForOldestUpload delegates to the next hook function in
|
||||
// the queue and stores the parameter and result values of this invocation.
|
||||
func (m *MockStore) GetCommitAndDateForOldestUpload(v0 context.Context, v1 int) (core.Option[store.CommitWithDate], error) {
|
||||
r0, r1 := m.GetCommitAndDateForOldestUploadFunc.nextHook()(v0, v1)
|
||||
m.GetCommitAndDateForOldestUploadFunc.appendCall(StoreGetCommitAndDateForOldestUploadFuncCall{v0, v1, r0, r1})
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// SetDefaultHook sets function that is called when the
|
||||
// GetCommitDateForOldestUpload method of the parent MockStore instance is
|
||||
// invoked and the hook queue is empty.
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) SetDefaultHook(hook func(context.Context, int) (core.Option[time.Time], error)) {
|
||||
// GetCommitAndDateForOldestUpload method of the parent MockStore instance
|
||||
// is invoked and the hook queue is empty.
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) SetDefaultHook(hook func(context.Context, int) (core.Option[store.CommitWithDate], error)) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
// PushHook adds a function to the end of hook queue. Each invocation of the
|
||||
// GetCommitDateForOldestUpload method of the parent MockStore instance
|
||||
// GetCommitAndDateForOldestUpload method of the parent MockStore instance
|
||||
// invokes the hook at the front of the queue and discards it. After the
|
||||
// queue is empty, the default hook function is invoked for any future
|
||||
// action.
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) PushHook(hook func(context.Context, int) (core.Option[time.Time], error)) {
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) PushHook(hook func(context.Context, int) (core.Option[store.CommitWithDate], error)) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
@ -2697,20 +2697,20 @@ func (f *StoreGetCommitDateForOldestUploadFunc) PushHook(hook func(context.Conte
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) SetDefaultReturn(r0 core.Option[time.Time], r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, int) (core.Option[time.Time], error) {
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) SetDefaultReturn(r0 core.Option[store.CommitWithDate], r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, int) (core.Option[store.CommitWithDate], error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) PushReturn(r0 core.Option[time.Time], r1 error) {
|
||||
f.PushHook(func(context.Context, int) (core.Option[time.Time], error) {
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) PushReturn(r0 core.Option[store.CommitWithDate], r1 error) {
|
||||
f.PushHook(func(context.Context, int) (core.Option[store.CommitWithDate], error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) nextHook() func(context.Context, int) (core.Option[time.Time], error) {
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) nextHook() func(context.Context, int) (core.Option[store.CommitWithDate], error) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
@ -2723,27 +2723,28 @@ func (f *StoreGetCommitDateForOldestUploadFunc) nextHook() func(context.Context,
|
||||
return hook
|
||||
}
|
||||
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) appendCall(r0 StoreGetCommitDateForOldestUploadFuncCall) {
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) appendCall(r0 StoreGetCommitAndDateForOldestUploadFuncCall) {
|
||||
f.mutex.Lock()
|
||||
f.history = append(f.history, r0)
|
||||
f.mutex.Unlock()
|
||||
}
|
||||
|
||||
// History returns a sequence of StoreGetCommitDateForOldestUploadFuncCall
|
||||
// objects describing the invocations of this function.
|
||||
func (f *StoreGetCommitDateForOldestUploadFunc) History() []StoreGetCommitDateForOldestUploadFuncCall {
|
||||
// History returns a sequence of
|
||||
// StoreGetCommitAndDateForOldestUploadFuncCall objects describing the
|
||||
// invocations of this function.
|
||||
func (f *StoreGetCommitAndDateForOldestUploadFunc) History() []StoreGetCommitAndDateForOldestUploadFuncCall {
|
||||
f.mutex.Lock()
|
||||
history := make([]StoreGetCommitDateForOldestUploadFuncCall, len(f.history))
|
||||
history := make([]StoreGetCommitAndDateForOldestUploadFuncCall, len(f.history))
|
||||
copy(history, f.history)
|
||||
f.mutex.Unlock()
|
||||
|
||||
return history
|
||||
}
|
||||
|
||||
// StoreGetCommitDateForOldestUploadFuncCall is an object that describes an
|
||||
// invocation of method GetCommitDateForOldestUpload on an instance of
|
||||
// StoreGetCommitAndDateForOldestUploadFuncCall is an object that describes
|
||||
// an invocation of method GetCommitAndDateForOldestUpload on an instance of
|
||||
// MockStore.
|
||||
type StoreGetCommitDateForOldestUploadFuncCall struct {
|
||||
type StoreGetCommitAndDateForOldestUploadFuncCall struct {
|
||||
// Arg0 is the value of the 1st argument passed to this method
|
||||
// invocation.
|
||||
Arg0 context.Context
|
||||
@ -2752,7 +2753,7 @@ type StoreGetCommitDateForOldestUploadFuncCall struct {
|
||||
Arg1 int
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 core.Option[time.Time]
|
||||
Result0 core.Option[store.CommitWithDate]
|
||||
// Result1 is the value of the 2nd result returned from this method
|
||||
// invocation.
|
||||
Result1 error
|
||||
@ -2760,13 +2761,13 @@ type StoreGetCommitDateForOldestUploadFuncCall struct {
|
||||
|
||||
// Args returns an interface slice containing the arguments of this
|
||||
// invocation.
|
||||
func (c StoreGetCommitDateForOldestUploadFuncCall) Args() []interface{} {
|
||||
func (c StoreGetCommitAndDateForOldestUploadFuncCall) Args() []interface{} {
|
||||
return []interface{}{c.Arg0, c.Arg1}
|
||||
}
|
||||
|
||||
// Results returns an interface slice containing the results of this
|
||||
// invocation.
|
||||
func (c StoreGetCommitDateForOldestUploadFuncCall) Results() []interface{} {
|
||||
func (c StoreGetCommitAndDateForOldestUploadFuncCall) Results() []interface{} {
|
||||
return []interface{}{c.Result0, c.Result1}
|
||||
}
|
||||
|
||||
|
||||
@ -670,6 +670,12 @@ type CodyProConfig struct {
|
||||
UseEmbeddedUI bool `json:"useEmbeddedUI,omitempty"`
|
||||
}
|
||||
|
||||
// CommitGraphUpdates description: Customize strategy used for commit graph updates
|
||||
type CommitGraphUpdates struct {
|
||||
// DefaultBranchOnly description: Disables precise code nav on non-default branches. Specify repo names using regex syntax.
|
||||
DefaultBranchOnly []string `json:"defaultBranchOnly,omitempty"`
|
||||
}
|
||||
|
||||
// Completions description: Configuration for the completions service.
|
||||
type Completions struct {
|
||||
// AccessToken description: The access token used to authenticate with the external completions provider. If using the default provider 'sourcegraph', and if 'licenseKey' is set, a default access token is generated.
|
||||
@ -1039,6 +1045,8 @@ type ExperimentalFeatures struct {
|
||||
CodeintelSyntacticIndexingEnabled bool `json:"codeintelSyntacticIndexing.enabled,omitempty"`
|
||||
// CodyContextIgnore description: Enabled filtering of remote Cody context based on repositories ./cody/ignore file
|
||||
CodyContextIgnore *bool `json:"codyContextIgnore,omitempty"`
|
||||
// CommitGraphUpdates description: Customize strategy used for commit graph updates
|
||||
CommitGraphUpdates *CommitGraphUpdates `json:"commitGraphUpdates,omitempty"`
|
||||
// CustomGitFetch description: JSON array of configuration that maps from Git clone URL domain/path to custom git fetch command. To enable this feature set environment variable `ENABLE_CUSTOM_GIT_FETCH` as `true` on gitserver.
|
||||
CustomGitFetch []*CustomGitFetchMapping `json:"customGitFetch,omitempty"`
|
||||
// DebugLog description: Turns on debug logging for specific debugging scenarios.
|
||||
@ -1138,6 +1146,7 @@ func (v *ExperimentalFeatures) UnmarshalJSON(data []byte) error {
|
||||
delete(m, "batchChanges.enablePerforce")
|
||||
delete(m, "codeintelSyntacticIndexing.enabled")
|
||||
delete(m, "codyContextIgnore")
|
||||
delete(m, "commitGraphUpdates")
|
||||
delete(m, "customGitFetch")
|
||||
delete(m, "debug.log")
|
||||
delete(m, "enableGithubInternalRepoVisibility")
|
||||
|
||||
@ -175,6 +175,21 @@
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"properties": {
|
||||
"commitGraphUpdates": {
|
||||
"description": "Customize strategy used for commit graph updates",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"defaultBranchOnly": {
|
||||
"description": "Disables precise code nav on non-default branches. Specify repo names using regex syntax.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"examples": ["github.com/myorg/huge-monorepo", "github.com/other-org/.*"]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"scipBasedAPIs": {
|
||||
"description": "Enable usage of new CodeGraph and usagesForSymbol APIs",
|
||||
"type": "boolean",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user