Documentation ¶
Overview ¶
Package datastore receives and caches the data from redis and the worker.
Index ¶
- type Datastore
- func (a Datastore) ApplauseConfig() (waitTime int, base int)
- func (d *Datastore) ChangedKeys(from, to int) ([]string, error)
- func (c *Datastore) ConfigValue(key string, v interface{}) error
- func (d *Datastore) CurrentID() int
- func (d *Datastore) Get(collection string, id int, v interface{}) error
- func (d *Datastore) GetAll() map[string]json.RawMessage
- func (d *Datastore) GetCollection(collection string) []json.RawMessage
- func (d *Datastore) GetMany(keys []string) map[string]json.RawMessage
- func (d *Datastore) GetModels(collection string, ids []int) []json.RawMessage
- func (h *Datastore) HasPerm(uid int, perm string) bool
- func (h *Datastore) InGroups(uid int, groups []int) bool
- func (h *Datastore) IsSuperadmin(uid int) bool
- func (d *Datastore) KeysChanged() ([]string, int, error)
- func (d *Datastore) LowestID() int
- func (r *Datastore) UserRequired(uid int) []string
- type DebugCondition
- type Projectors
- type RedisConn
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 (*Datastore) ChangedKeys ¶
ChangedKeys returns the keys that have changed between from and to from redis. from is not inclusive, to is inclusiv.
func (*Datastore) ConfigValue ¶
func (*Datastore) Get ¶
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) IsSuperadmin ¶
func (*Datastore) KeysChanged ¶
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) UserRequired ¶
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.