models

package
v0.0.0-...-e560ebb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2021 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RepositoryStaleIndexingDuration defines maximum duration between
	// full_scan_lock refreshes after which indexing will be considered
	// incomplete. At that point, any backend instance of cr-rev can take
	// over indexing.
	RepositoryStaleIndexingDuration = 1 * time.Hour
)

Variables

This section is empty.

Functions

func PersistCommits

func PersistCommits(ctx context.Context, commits []*common.GitCommit) (bool, error)

PersistCommits converts list of commits to Datastore structs and stores them in Datastore. It returns (true, nil) if last commit in the list is already in database, indicating that further traversal may not be needed.

Types

type Commit

type Commit struct {
	ID            string `gae:"$id"`
	Host          string
	Repository    string
	CommitHash    string
	CommitMessage string `gae:",noindex"`

	// PositionRef is extracted from Git footer. If the footer is not
	// present, it has zero value. If non-zero, PositionNumber is also
	// non-zero.
	PositionRef string

	// PositionNumber is extracted from Git footer. If the footer is not
	// present, it has zero value. If non-zero, PositionRef is also
	// non-zero.
	PositionNumber int
}

Commit represents a document in datastore. Commit is generated and persisted exclusively by the backend service, during initial repository import or while receiving pubsub messages. Once persisted, commit document shouldn't be changed. The frontend service queries commits either by {CommitHash} or by {Repository, PositionRef, PositionNumber}.

func FindCommitsByHash

func FindCommitsByHash(ctx context.Context, hash string) ([]*Commit, error)

FindCommitsByHash returns all commits that match exact hash. Same hash is likely to happen only on mirrors and forks.

func (Commit) SameRepoAs

func (c1 Commit) SameRepoAs(c2 Commit) bool

SameRepoAs compares itself against commit c2 and returns true if host and repository are identical.

type RepoID

type RepoID struct {
	Host       string
	Repository string
}

RepoID uniquely identifies a repository. It's used as a primary key for the Repository kind.

func (*RepoID) FromProperty

func (rID *RepoID) FromProperty(p datastore.Property) error

FromProperty deserializes RepoID from its string representation.

func (*RepoID) ToProperty

func (rID *RepoID) ToProperty() (p datastore.Property, err error)

ToProperty serializes RepoID into string representation, separated by slash.

type Repository

type Repository struct {
	ID RepoID `gae:"$id"`

	// FullScanLastRun holds information when was last successful full
	// import. Zero value means the repository was never fully indexed.
	FullScanLastRun time.Time `gae:",noindex"`

	// FullScanLeaseStartTime, if non-zero value, indicates on-going
	// indexing. The indexing process should periodically update this
	// value. If the last update was longer than
	// RepositoryStaleIndexingDuration, the import process is considered
	// stalled (e.g. crashed, networking partition) and a new import job
	// can be triggered.
	FullScanLeaseStartTime time.Time

	// FullScanLeaseHostname tracks which hostname has the lease for the
	// repository.
	FullScanLeaseHostname string `gae:",noindex"`
}

Repository represents a document in datastore. It stores information about indexed repository. Before new repository is indexed, cr-rev creates entry in datastore with FullScanLock set to current time and FullScanLastRun to zero value. On successful execution, FullScanLastRun is set to current time.

func (*Repository) ExtendLease

func (r *Repository) ExtendLease(currentTime time.Time)

ExtendLease extends currently active lease. This function doesn't check lease ownership.

func (*Repository) IsScanRequired

func (r *Repository) IsScanRequired(currentTime time.Time) bool

IsScanRequired returns true if full repository scan is required. This happens if repository was never indexed or if previous lease expired and left this repository partially indexed.

func (*Repository) SetIndexingCompleted

func (r *Repository) SetIndexingCompleted(currentTime time.Time)

SetIndexingCompleted marks Repository as successfully indexed and removes lease.

func (*Repository) SetStartIndexing

func (r *Repository) SetStartIndexing(currentTime time.Time, hostname string)

SetStartIndexing marks Repository for initial import and sets lease information. It is on client to ensure lease is renewed periodically, by calling ExtendLease

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL