stores

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const CurrentGameDocumentVersion = 2
View Source
const MaxExpirationSeconds = 10 * 24 * 60 * 60 // 10 days
View Source
const RedisDocPrefix = "gdoc:"
View Source
const RedisExpirationSeconds = 15 * 60 // 15 minutes
View Source
const RedisMutexPrefix = "gdocmutex:"

Variables

View Source
var ErrDoesNotExist = errors.New("does not exist")

Functions

func MigrateGameDocument

func MigrateGameDocument(cfg *config.Config, gdoc *ipc.GameDocument) error

MigrateGameDocument performs an in-place migration of a GameDocument. It does not save it back to any store. This is meant to be used as a temporary function; we should migrate the database permanently after having this in production for a bit while people are on old versions.

Types

type BroadcastGame

type BroadcastGame struct {
	GameUUID        string
	CreatorUUID     string
	CreatorUsername string
	Private         bool
	Finished        bool
	Players         []*ipc.PlayerInfo
	Lexicon         string
	Created         time.Time
}

type DBStore

type DBStore struct {
	// contains filtered or unexported fields
}

func NewDBStore

func NewDBStore(p *pgxpool.Pool) (*DBStore, error)

func (*DBStore) CreateAnnotatedGame

func (s *DBStore) CreateAnnotatedGame(ctx context.Context, creatorUUID string, gameUUID string,
	private bool, quickdata *entity.Quickdata, req *ipc.GameRequest) error

func (*DBStore) DeleteAnnotatedGame

func (s *DBStore) DeleteAnnotatedGame(ctx context.Context, uuid string) error

func (*DBStore) Disconnect

func (s *DBStore) Disconnect()

func (*DBStore) GameIsDone

func (s *DBStore) GameIsDone(ctx context.Context, gid string) (bool, error)

func (*DBStore) GameOwnedBy

func (s *DBStore) GameOwnedBy(ctx context.Context, gid, uid string) (bool, error)

func (*DBStore) GamesForEditor

func (s *DBStore) GamesForEditor(ctx context.Context, editorID string, unfinished bool, limit, offset int) ([]*BroadcastGame, error)

func (*DBStore) MarkAnnotatedGameDone

func (s *DBStore) MarkAnnotatedGameDone(ctx context.Context, uuid string) error

func (*DBStore) OutstandingGames

func (s *DBStore) OutstandingGames(ctx context.Context, creatorUUID string) ([]*BroadcastGame, error)

OutstandingGames returns a list of game IDs for games that are not yet done being annotated. The system will only allow a certain number of games to remain undone for an annotator.

func (*DBStore) UpdateAnnotatedGameQuickdata

func (s *DBStore) UpdateAnnotatedGameQuickdata(ctx context.Context, uuid string, quickdata *entity.Quickdata) error

type GameDocumentStore

type GameDocumentStore struct {
	// contains filtered or unexported fields
}

func NewGameDocumentStore

func NewGameDocumentStore(cfg *config.Config, r *redis.Pool, db *pgxpool.Pool) (*GameDocumentStore, error)

func (*GameDocumentStore) DeleteDocument

func (gs *GameDocumentStore) DeleteDocument(ctx context.Context, uuid string) error

func (*GameDocumentStore) DisconnectRDB

func (gs *GameDocumentStore) DisconnectRDB()

func (*GameDocumentStore) GetDocument

func (gs *GameDocumentStore) GetDocument(ctx context.Context, uuid string, lock bool) (*MaybeLockedDocument, error)

GetDocument gets a game document from the store. It tries Redis first, then S3 if not found in Redis. The lock parameter is ignored if this item is not in Redis. If it is in Redis, and lock is true, the document is locked. The SetDocument function will try to unlock it. If it locked, we return the lock value for future usage.

func (*GameDocumentStore) SetDocument

func (gs *GameDocumentStore) SetDocument(ctx context.Context, gdoc *ipc.GameDocument) error

SetDocument should be called to set the initial document in redis.

func (*GameDocumentStore) UnlockDocument

func (gs *GameDocumentStore) UnlockDocument(ctx context.Context, doc *MaybeLockedDocument) error

func (*GameDocumentStore) UpdateDocument

func (gs *GameDocumentStore) UpdateDocument(ctx context.Context, doc *MaybeLockedDocument) error

UpdateDocument makes an atomic update to document in the Redis store. If the game is done, though, it will write it to S3 and expire it from the Redis store.

type MaybeLockedDocument

type MaybeLockedDocument struct {
	*ipc.GameDocument
	LockValue string
}

MaybeLockedDocument wraps a game document but also contains a value. If the value is not blank then the document is locked.

Jump to

Keyboard shortcuts

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