Documentation ¶
Index ¶
- Constants
- type Cache
- func (c *Cache) CachedCount(ctx context.Context) int
- func (c *Cache) Count(ctx context.Context) (int64, error)
- func (c *Cache) Create(ctx context.Context, game *entity.Game) error
- func (c *Cache) CreateRaw(ctx context.Context, game *entity.Game, gt pb.GameType) error
- func (c *Cache) Disconnect()
- func (c *Cache) Exists(ctx context.Context, id string) (bool, error)
- func (c *Cache) GameEventChan() chan<- *entity.EventWrapper
- func (c *Cache) Get(ctx context.Context, id string) (*entity.Game, error)
- func (c *Cache) GetHistory(ctx context.Context, id string) (*macondopb.GameHistory, error)
- func (c *Cache) GetMetadata(ctx context.Context, id string) (*pb.GameInfoResponse, error)
- func (c *Cache) GetRecentGames(ctx context.Context, username string, numGames int, offset int) (*pb.GameInfoResponses, error)
- func (c *Cache) GetRecentTourneyGames(ctx context.Context, tourneyID string, numGames int, offset int) (*pb.GameInfoResponses, error)
- func (c *Cache) GetRematchStreak(ctx context.Context, originalRequestId string) (*gs.StreakInfoResponse, error)
- func (c *Cache) ListActive(ctx context.Context, tourneyID string, bust bool) (*pb.GameInfoResponses, error)
- func (c *Cache) Set(ctx context.Context, game *entity.Game) error
- func (c *Cache) SetGameEventChan(ch chan<- *entity.EventWrapper)
- func (c *Cache) SetReady(ctx context.Context, gid string, pidx int) (int, error)
- func (c *Cache) Unload(ctx context.Context, id string)
- type DBStore
- func (s *DBStore) CachedCount(ctx context.Context) int
- func (s *DBStore) Count(ctx context.Context) (int64, error)
- func (s *DBStore) Create(ctx context.Context, g *entity.Game) error
- func (s *DBStore) CreateRaw(ctx context.Context, g *entity.Game, gt pb.GameType) error
- func (s *DBStore) Disconnect()
- func (s *DBStore) Exists(ctx context.Context, id string) (bool, error)
- func (s *DBStore) GameEventChan() chan<- *entity.EventWrapper
- func (s *DBStore) Get(ctx context.Context, id string) (*entity.Game, error)
- func (s *DBStore) GetHistory(ctx context.Context, id string) (*macondopb.GameHistory, error)
- func (s *DBStore) GetMetadata(ctx context.Context, id string) (*pb.GameInfoResponse, error)
- func (s *DBStore) GetRecentGames(ctx context.Context, username string, numGames int, offset int) (*pb.GameInfoResponses, error)
- func (s *DBStore) GetRecentTourneyGames(ctx context.Context, tourneyID string, numGames int, offset int) (*pb.GameInfoResponses, error)
- func (s *DBStore) GetRematchStreak(ctx context.Context, originalRequestId string) (*gs.StreakInfoResponse, error)
- func (s *DBStore) ListActive(ctx context.Context, tourneyID string) (*pb.GameInfoResponses, error)
- func (s *DBStore) ListAllIDs(ctx context.Context) ([]string, error)
- func (s *DBStore) Set(ctx context.Context, g *entity.Game) error
- func (s *DBStore) SetGameEventChan(c chan<- *entity.EventWrapper)
- func (s *DBStore) SetReady(ctx context.Context, gid string, pidx int) (int, error)
- type MemoryStore
Constants ¶
const ( // Note: above is overly optimistic. // It seems each cache slot is taking about 750kB. // That's in addition to about 200MB base. // Reduced cache cap accordingly. CacheCap = 400 )
const (
MaxRecentGames = 1000
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct { sync.RWMutex // used for the activeGames cache. // contains filtered or unexported fields }
Cache will reside in-memory, and will be per-node. If we add more nodes we will need to make sure only the right nodes respond to game requests.
func (*Cache) Disconnect ¶
func (c *Cache) Disconnect()
func (*Cache) GameEventChan ¶
func (c *Cache) GameEventChan() chan<- *entity.EventWrapper
func (*Cache) GetHistory ¶
func (*Cache) GetMetadata ¶
Similar to get but does not unmarshal the stats and timers and does not play the game
func (*Cache) GetRecentGames ¶
func (*Cache) GetRecentTourneyGames ¶
func (*Cache) GetRematchStreak ¶
func (c *Cache) GetRematchStreak(ctx context.Context, originalRequestId string) (*gs.StreakInfoResponse, error)
Just call the DB implementation for now
func (*Cache) ListActive ¶
func (c *Cache) ListActive(ctx context.Context, tourneyID string, bust bool) (*pb.GameInfoResponses, error)
ListActive lists all active games in the given tournament ID (optional) or site-wide if not provided. If `bust` is true, we will always query the backing store.
func (*Cache) Set ¶
Set sets a game in the cache, AND in the backing store. This ensures if the node crashes the game doesn't just vanish.
func (*Cache) SetGameEventChan ¶
func (c *Cache) SetGameEventChan(ch chan<- *entity.EventWrapper)
SetGameEventChan sets the game event channel to the passed in channel.
type DBStore ¶
type DBStore struct {
// contains filtered or unexported fields
}
DBStore is a postgres-backed store for games.
func NewDBStore ¶
NewDBStore creates a new DB store for games.
func (*DBStore) Disconnect ¶
func (s *DBStore) Disconnect()
func (*DBStore) GameEventChan ¶
func (s *DBStore) GameEventChan() chan<- *entity.EventWrapper
GameEventChan returns the game event channel for all games.
func (*DBStore) Get ¶
Get creates an instantiated entity.Game from the database. This function should almost never be called during a live game. The db store should be wrapped with a cache. Only API nodes that have this game in its cache should respond to requests.
func (*DBStore) GetHistory ¶
func (*DBStore) GetMetadata ¶
GetMetadata gets metadata about the game, but does not actually play the game.
func (*DBStore) GetRecentGames ¶
func (*DBStore) GetRecentTourneyGames ¶
func (*DBStore) GetRematchStreak ¶
func (*DBStore) ListActive ¶
func (*DBStore) ListAllIDs ¶
List all game IDs, ordered by date played. Should not be used by anything other than debug or migration code when the db is still small.
func (*DBStore) Set ¶
Set takes in a game entity that _already exists_ in the DB, and writes it to the database.
func (*DBStore) SetGameEventChan ¶
func (s *DBStore) SetGameEventChan(c chan<- *entity.EventWrapper)
SetGameEventChan sets the game event channel to the passed in channel.
type MemoryStore ¶
MemoryStore is a purely in-memory store of a game. In the real final implementation, we will probably use a Postgres-backed memory store. Due to the nature of this app, we will always need to have a persistent in-memory instantiation of a game.
func NewMemoryStore ¶
func NewMemoryStore() *MemoryStore
func (*MemoryStore) Create ¶
Create creates a game in the store initially. Make it the same function as Set essentially.