datastore

package
v0.0.0-...-d450093 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package datastore receives and caches the data from redis and the worker.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Datastore

type Datastore struct {
	*Projectors
	// contains filtered or unexported fields
}

Datastore holds the connection to OpenSlides and Redis.

func New

func New(redisConn RedisConn, requiredUsers map[string]func(json.RawMessage) (map[int]bool, string, error), projectorSlides map[string]projector.Callable, closed <-chan struct{}) (*Datastore, error)

New returns an initialized Datastore instance.

func (Datastore) ApplauseConfig

func (a Datastore) ApplauseConfig() (waitTime int, base int)

func (*Datastore) ChangedKeys

func (d *Datastore) ChangedKeys(from, to int) ([]string, error)

ChangedKeys returns the keys that have changed between from and to from redis. from is not inclusive, to is inclusiv.

func (*Datastore) ConfigValue

func (c *Datastore) ConfigValue(key string, v interface{}) error

func (*Datastore) CurrentID

func (d *Datastore) CurrentID() int

CurrentID returns the highest id in the datastore.

func (*Datastore) Get

func (d *Datastore) Get(collection string, id int, v interface{}) error

Get sets the attribute v to the value the collection:id. Returns an error with the method `DoesNotExist() string` if the value does not exist.

v has to be a pointer.

func (*Datastore) GetAll

func (d *Datastore) GetAll() map[string]json.RawMessage

GetAll returns all data.

func (*Datastore) GetCollection

func (d *Datastore) GetCollection(collection string) []json.RawMessage

GetCollection gets all elements of one collection.

func (*Datastore) GetMany

func (d *Datastore) GetMany(keys []string) map[string]json.RawMessage

GetMany returns the values for the given keys.

func (*Datastore) GetModels

func (d *Datastore) GetModels(collection string, ids []int) []json.RawMessage

GetModels returns each element from collection that is in the ids slide.

func (*Datastore) HasPerm

func (h *Datastore) HasPerm(uid int, perm string) bool

func (*Datastore) InGroups

func (h *Datastore) InGroups(uid int, groups []int) bool

func (*Datastore) IsSuperadmin

func (h *Datastore) IsSuperadmin(uid int) bool

func (*Datastore) KeysChanged

func (d *Datastore) KeysChanged() ([]string, int, error)

KeysChanged blocks until there is new data. It updates the internal cache and returns the changed keys and the new change id.

If the datastore is closed then it return nil, 0, nil.

func (*Datastore) LowestID

func (d *Datastore) LowestID() int

LowestID returns the lowest id in the datastore.

func (*Datastore) UserRequired

func (r *Datastore) UserRequired(uid int) []string

UserRequired tells, if the uid is required by another element.

An empty result means, that the uid is not required.

If the user is required, a list of permissions is returned. If the client has one of the permission, it should see the user.

type DebugCondition

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

DebugCondition is used to get informations, in which constellation the database was invalid.

To do this, create a DebugCondition at the beginning of a function and after each state-ceck, append the condition of the database.

If an error happens, that could be a doesNotExistError, then wrap the error with DebugCondition.Error().

Example:

func foo(ds DataStore, u User) error{
con := new(datastore.DebugCondition)
if u.IsPresent() {
	return nil
}
conn.Append("User is not present")

var username struct {
	Username string
}
if err := ds.Get("users/user:"+u.ID, &username); err != nil {
	return conn.Error("getting username: %w", err)
}
return nil
}

func (*DebugCondition) Append

func (c *DebugCondition) Append(format string, a ...interface{})

Append adds one conditions description

func (*DebugCondition) Error

func (c *DebugCondition) Error(format string, a ...interface{}) error

Error creates an error under the condition.

func (*DebugCondition) Sub

func (c *DebugCondition) Sub() *DebugCondition

Sub creates a new Condition that contains all conditions of the given condition.

type Projectors

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

Projectors holds the data of all projectors.

func NewProjectors

func NewProjectors(ds projector.Datastore, ps map[string]projector.Callable, closed <-chan struct{}) *Projectors

NewProjectors returns a new projector instance.

func (*Projectors) ProjectorData

func (p *Projectors) ProjectorData(ctx context.Context, tid uint64) (uint64, map[int]json.RawMessage, error)

ProjectorData returns the data of every changed projector.

Blocks untils the service or the context is closed or at least one projector has changed.

func (*Projectors) Update

func (p *Projectors) Update(data map[string]json.RawMessage) error

Update updates the cache of the projector.

type RedisConn

type RedisConn interface {
	FullData() (data map[string]json.RawMessage, max int, min int, err error)
	Update(<-chan struct{}) ([]byte, error)
	ChangedKeys(from, to int) ([]string, error)
	Data(keys []string) (map[string]json.RawMessage, error)
}

RedisConn calls all needed redis commands.

Jump to

Keyboard shortcuts

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