firestore

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("no docs found")

Functions

This section is empty.

Types

type CacheKey

type CacheKey string

type Client

type Client struct {
	*firestore.Client
	// contains filtered or unexported fields
}

func NewFirestoreClient

func NewFirestoreClient(ctx context.Context, client *firestore.Client, debug bool) (*Client, error)

func (*Client) GetAllSongsID

func (c *Client) GetAllSongsID(ctx context.Context) ([]pkg.SongID, error)

func (*Client) GetSongByID

func (c *Client) GetSongByID(ctx context.Context, id pkg.SongID) (*pkg.Song, error)

func (*Client) GetUserSong

func (c *Client) GetUserSong(ctx context.Context, id pkg.SongID, user string) (*pkg.Song, error)

func (*Client) SetSong

func (c *Client) SetSong(ctx context.Context, song *pkg.Song) error

func (*Client) SetSongForced

func (c *Client) SetSongForced(ctx context.Context, song *pkg.Song) error

func (*Client) SetUserSong

func (c *Client) SetUserSong(ctx context.Context, song *pkg.Song, user string) error

func (*Client) UpsertSongIncPlaybacks

func (c *Client) UpsertSongIncPlaybacks(ctx context.Context, new *pkg.Song) (int, error)

UpsertSongIncPlaybacks We don't use it because our cash of songs is always consistent As we have only one writer to the song db - this bot

func (*Client) WriteBatch

func (c *Client) WriteBatch(ctx context.Context, songs []*pkg.Song) error

type Item

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

type Service

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

func NewFirestoreService

func NewFirestoreService(ctx context.Context, client *Client, songs *SongsCache) (*Service, error)

func (*Service) GetRandomSongs

func (s *Service) GetRandomSongs(ctx context.Context, n int) ([]*pkg.Song, error)

func (*Service) GetSong

func (s *Service) GetSong(ctx context.Context, id pkg.SongID) (*pkg.Song, error)

func (*Service) IncrementUserRequests

func (s *Service) IncrementUserRequests(ctx context.Context, song *pkg.Song, userID string)

func (*Service) SetSong

func (s *Service) SetSong(ctx context.Context, song *pkg.Song) error

func (*Service) UpsertSongIncPlaybacks

func (s *Service) UpsertSongIncPlaybacks(ctx context.Context, new *pkg.Song) (int, error)

type SongsCache

type SongsCache struct {
	sync.Mutex
	// contains filtered or unexported fields
}

SongsCache TODO: there is no need in this cache because firestore.client has it's own that can be reused

func NewSongsCache

func NewSongsCache(ctx context.Context, expirationTime time.Duration) *SongsCache

func (*SongsCache) Clear

func (c *SongsCache) Clear()

func (*SongsCache) Get

func (c *SongsCache) Get(k string) (*pkg.Song, bool)

func (*SongsCache) KeyFromID

func (c *SongsCache) KeyFromID(s pkg.SongID) string

func (*SongsCache) Set

func (c *SongsCache) Set(k string, song *pkg.Song)

Jump to

Keyboard shortcuts

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