memstore

package
v1.24.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyMap          = errors.New("memstore: cannot select from an empty map")
	ErrEmptySlice        = errors.New("memstore: cannot select from an empty slice")
	ErrLenMismatch       = errors.New("memstore: cannot select from a map, not enough elements")
	ErrTeamNotFound      = errors.New("memstore: team not found")
	ErrUserNotSet        = errors.New("memstore: user is not set")
	ErrTeamStoreEmpty    = errors.New("memstore: team store is empty")
	ErrChannelStoreEmpty = errors.New("memstore: channel store is empty")
	ErrChannelNotFound   = errors.New("memstore: channel not found")
	ErrPostNotFound      = errors.New("memstore: post not found")
	ErrInvalidData       = errors.New("memstore: invalid data found")
	ErrThreadNotFound    = errors.New("memstore: thread not found")
	ErrMaxAttempts       = errors.New("memstore: maximum number of attempts tried")
	ErrDraftNotFound     = errors.New("memstore: draft not found")
)

Functions

func SetRandomSeed

func SetRandomSeed() int64

SetRandomSeed sets the global random seed and returns it's value.

Types

type CQueue

type CQueue[T any] struct {
	// contains filtered or unexported fields
}

CQueue is a basic implementation of a circular queue of fixed size.

func NewCQueue

func NewCQueue[T any](size int) (*CQueue[T], error)

NewCQueue creates and returns a pointer to a queue of the given size.

func (*CQueue[T]) Get

func (q *CQueue[T]) Get() *T

Get returns a pointer to the next element in the queue. In case this is nil, data for it will be allocated before returning.

func (*CQueue[T]) Reset

func (q *CQueue[T]) Reset()

Reset re-initializes the queue to be reused.

type Config

type Config struct {
	MaxStoredPosts          int // The maximum number of posts to be stored.
	MaxStoredUsers          int // The maximum number of users to be stored.
	MaxStoredChannelMembers int // The maximum number of channel members to be stored.
	MaxStoredStatuses       int // The maximum number of statuses to be stored.
	MaxStoredThreads        int // The maximum number of statuses to be stored.
	MaxStoredReactions      int // The maximum number of reactions to be stored.
}

Config holds information used to create a new MemStore.

func (*Config) IsValid

func (c *Config) IsValid() error

IsValid checks whether a Config is valid or not. Returns an error if the validation fails.

func (*Config) SetDefaults

func (c *Config) SetDefaults()

SetDefaults sets default values to the config.

type MemStore

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

MemStore is a simple implementation of MutableUserStore which holds all data in memory.

func New

func New(config *Config) (*MemStore, error)

New returns a new instance of MemStore with the given config. If config is nil, defaults will be used.

func (*MemStore) AddChannelBookmark added in v1.23.0

func (s *MemStore) AddChannelBookmark(bookmark *model.ChannelBookmarkWithFileInfo) error

AddChannelBookmark stores the bookmark.

func (*MemStore) Channel

func (s *MemStore) Channel(channelId string) (*model.Channel, error)

Channel returns the channel for the given channelId.

func (*MemStore) ChannelBookmarks added in v1.23.0

func (s *MemStore) ChannelBookmarks(channelId string) []*model.ChannelBookmarkWithFileInfo

ChannelBookmarks returns all bookmarks for the specified channel.

func (*MemStore) ChannelMember

func (s *MemStore) ChannelMember(channelId, userId string) (model.ChannelMember, error)

ChannelMember returns the channel member for the given channelId and userId.

func (*MemStore) ChannelMembers

func (s *MemStore) ChannelMembers(channelId string) (model.ChannelMembers, error)

ChannelMembers returns a list of members for the specified channel.

func (*MemStore) ChannelPosts

func (s *MemStore) ChannelPosts(channelId string) ([]*model.Post, error)

ChannelPosts returns all posts for the specified channel.

func (*MemStore) ChannelPostsSorted

func (s *MemStore) ChannelPostsSorted(channelId string, asc bool) ([]*model.Post, error)

ChannelPostsSorted returns all posts for specified channel, sorted by CreateAt.

func (*MemStore) ChannelStats added in v1.3.0

func (s *MemStore) ChannelStats(channelId string) (*model.ChannelStats, error)

ChannelStats returns statistics for the given channelId.

func (*MemStore) ChannelView

func (s *MemStore) ChannelView(channelId string) (int64, error)

ChannelView returns the timestamp of the last view for the given channelId.

func (*MemStore) Channels

func (s *MemStore) Channels(teamId string) ([]model.Channel, error)

Channels returns all the channels for a team. This means no DM/GM channels are returned.

func (*MemStore) Clear

func (s *MemStore) Clear()

Clear resets the store and removes all entries with the exception of the user object and state information (current team/channel) which are preserved.

func (*MemStore) ClientConfig added in v1.3.0

func (s *MemStore) ClientConfig() map[string]string

ClientConfig returns the limited server configuration settings for user.

func (*MemStore) Config

func (s *MemStore) Config() model.Config

Config returns the server configuration settings.

func (*MemStore) CurrentChannel

func (s *MemStore) CurrentChannel() (*model.Channel, error)

GetCurrentChannel returns the channel the user is currently viewing.

func (*MemStore) CurrentTeam

func (s *MemStore) CurrentTeam() (*model.Team, error)

GetCurrentTeam returns the currently selected team for the user.

func (*MemStore) DeleteChannelBookmark added in v1.23.0

func (s *MemStore) DeleteChannelBookmark(bookmarkId string) error

DeleteChannelBookmark deletes a given bookmark.

func (*MemStore) DeletePost

func (s *MemStore) DeletePost(postId string) error

DeletePost deletes the specified post.

func (*MemStore) DeleteReaction

func (s *MemStore) DeleteReaction(reaction *model.Reaction) (bool, error)

DeleteReaction deletes the given reaction. It returns whether or not the reaction was deleted.

func (*MemStore) Email

func (s *MemStore) Email() string

Email returns the email for the stored user.

func (*MemStore) FeatureFlags added in v1.10.0

func (s *MemStore) FeatureFlags() map[string]bool

FeatureFlags returns a map of the features flags stored in the client config.

func (*MemStore) FileInfoForPost

func (s *MemStore) FileInfoForPost(postId string) ([]*model.FileInfo, error)

FileInfoForPost returns the FileInfo for the specified post, if any.

func (*MemStore) GetUser

func (s *MemStore) GetUser(userId string) (model.User, error)

GetUser returns the user for the given userId.

func (*MemStore) Id

func (s *MemStore) Id() string

Id returns the id for the stored user.

func (*MemStore) IsTeamMember added in v1.10.0

func (s *MemStore) IsTeamMember(teamId, userId string) bool

IsTeamMember returns whether the user is part of the team.

func (*MemStore) MarkAllThreadsInTeamAsRead added in v1.5.0

func (s *MemStore) MarkAllThreadsInTeamAsRead(teamId string) error

MarkAllThreadsInTeamAsRead marks all threads in the given team as read

func (*MemStore) Password

func (s *MemStore) Password() string

Password returns the password for the stored user.

func (*MemStore) PerformanceReport added in v1.23.0

func (s *MemStore) PerformanceReport() (*model.PerformanceReport, error)

func (*MemStore) Post

func (s *MemStore) Post(postId string) (*model.Post, error)

Post returns the post for the given postId.

func (*MemStore) PostsIdsSince

func (s *MemStore) PostsIdsSince(ts int64) ([]string, error)

PostsIdsSince returns a list of post ids for posts created after a specified timestamp in milliseconds.

func (*MemStore) PostsWithAckRequests added in v1.10.0

func (s *MemStore) PostsWithAckRequests() ([]string, error)

PostsWithAckRequests returns IDs of the posts that asked for acknowledgment.

func (*MemStore) Preferences

func (s *MemStore) Preferences() (model.Preferences, error)

Preferences returns the preferences for the stored user.

func (*MemStore) ProfileImageLastUpdated added in v1.10.0

func (s *MemStore) ProfileImageLastUpdated(userId string) (int, error)

ProfileImageLastUpdated returns the etag returned by the server when first fetched, which is the last time the picture was updated, or zero if the image is not stored.

func (*MemStore) RandomCategory added in v1.5.0

func (s *MemStore) RandomCategory(teamID string) (model.SidebarCategoryWithChannels, error)

func (*MemStore) RandomChannel

func (s *MemStore) RandomChannel(teamId string, st store.SelectionType) (model.Channel, error)

RandomChannel returns a random channel for the given teamId for the current user.

func (*MemStore) RandomChannelMember

func (s *MemStore) RandomChannelMember(channelId string) (model.ChannelMember, error)

RandomChannelMember returns a random channel member for a channel.

func (*MemStore) RandomDraftForTeam added in v1.20.0

func (s *MemStore) RandomDraftForTeam(teamId string) (string, error)

RandomDraftForTeam returns a random draft id for the given team

func (*MemStore) RandomEmoji

func (s *MemStore) RandomEmoji() (model.Emoji, error)

RandomEmoji returns a random emoji.

func (*MemStore) RandomPost

func (s *MemStore) RandomPost(st store.SelectionType) (model.Post, error)

RandomPost returns a random post.

func (*MemStore) RandomPostForChannel

func (s *MemStore) RandomPostForChannel(channelId string) (model.Post, error)

RandomPostForChannel returns a random post for the given channel.

func (*MemStore) RandomPostForChannelByUser

func (s *MemStore) RandomPostForChannelByUser(channelId, userId string) (model.Post, error)

RandomPostForChannelForUser returns a random post for the given channel made by the given user.

func (*MemStore) RandomReplyPostForChannel added in v1.5.0

func (s *MemStore) RandomReplyPostForChannel(channelId string) (model.Post, error)

RandomReplyPostForChannel returns a random reply post for the given channel.

func (*MemStore) RandomTeam

func (s *MemStore) RandomTeam(st store.SelectionType) (model.Team, error)

RandomTeam returns a random team for the current user.

func (*MemStore) RandomTeamMember

func (s *MemStore) RandomTeamMember(teamId string) (model.TeamMember, error)

RandomTeamMember returns a random team member for a team.

func (*MemStore) RandomThread added in v1.5.0

func (s *MemStore) RandomThread() (model.ThreadResponse, error)

RandomThread returns a random post.

func (*MemStore) RandomUser

func (s *MemStore) RandomUser() (model.User, error)

RandomUser returns a random user from the set of users.

func (*MemStore) RandomUsers

func (s *MemStore) RandomUsers(n int) ([]model.User, error)

RandomUsers returns N random users from the set of users.

func (*MemStore) Reactions

func (s *MemStore) Reactions(postId string) ([]model.Reaction, error)

Reactions returns the reactions for the specified post.

func (*MemStore) RemoveChannelMember

func (s *MemStore) RemoveChannelMember(channelId string, userId string) error

RemoveChannelMember removes the channel member for the specified channel and user.

func (*MemStore) RemoveTeamMember

func (s *MemStore) RemoveTeamMember(teamId string, userId string) error

RemoveTeamMember removes the team member for the specified team and user..

func (*MemStore) Roles

func (s *MemStore) Roles() ([]model.Role, error)

Roles returns the roles of the user.

func (*MemStore) ServerVersion added in v1.2.0

func (s *MemStore) ServerVersion() (string, error)

ServerVersion returns the server version string.

func (*MemStore) SetCategories added in v1.5.0

func (s *MemStore) SetCategories(teamID string, sidebarCategories *model.OrderedSidebarCategories) error

func (*MemStore) SetChannel

func (s *MemStore) SetChannel(channel *model.Channel) error

SetChannel stores the given channel.

func (*MemStore) SetChannelBookmarks added in v1.23.0

func (s *MemStore) SetChannelBookmarks(bookmarks []*model.ChannelBookmarkWithFileInfo) error

SetChannelBookmarks stores the given bookmarks.

func (*MemStore) SetChannelMember

func (s *MemStore) SetChannelMember(channelId string, channelMember *model.ChannelMember) error

SetChannelMember stores the given channel member.

func (*MemStore) SetChannelMembers

func (s *MemStore) SetChannelMembers(channelMembers model.ChannelMembers) error

SetChannelMembers stores the given channel members in the store.

func (*MemStore) SetChannelStats added in v1.3.0

func (s *MemStore) SetChannelStats(channelId string, stats *model.ChannelStats) error

SetChannelStats stores statistics for the given channelId.

func (*MemStore) SetChannelView

func (s *MemStore) SetChannelView(channelId string) error

SetChannelView marks the given channel as viewed and updates the store with the current timestamp.

func (*MemStore) SetChannels

func (s *MemStore) SetChannels(channels []*model.Channel) error

SetChannels adds the given channels to the store.

func (*MemStore) SetClientConfig added in v1.3.0

func (s *MemStore) SetClientConfig(config map[string]string)

Set ClientConfig stores the given limited configuration settings.

func (*MemStore) SetConfig

func (s *MemStore) SetConfig(config *model.Config)

SetConfig stores the given configuration settings.

func (*MemStore) SetCurrentChannel

func (s *MemStore) SetCurrentChannel(channel *model.Channel) error

SetCurrentChannel stores the channel the user is currently viewing.

func (*MemStore) SetCurrentTeam

func (s *MemStore) SetCurrentTeam(team *model.Team) error

SetCurrentTeam sets the currently selected team for the user.

func (*MemStore) SetDraft added in v1.20.0

func (s *MemStore) SetDraft(teamId, id string, draft *model.Draft) error

SetDraft stores the draft for the given teamId, and channelId or rootId.

func (*MemStore) SetDrafts added in v1.20.0

func (s *MemStore) SetDrafts(teamId string, drafts []*model.Draft) error

SetDrafts stores the given drafts.

func (*MemStore) SetEmojis

func (s *MemStore) SetEmojis(emoji []*model.Emoji) error

SetEmojis stores the given emojis.

func (*MemStore) SetLicense

func (s *MemStore) SetLicense(license map[string]string) error

SetLicense stores the given license in the store.

func (*MemStore) SetPerformanceReport added in v1.23.0

func (s *MemStore) SetPerformanceReport(report *model.PerformanceReport)

func (*MemStore) SetPost

func (s *MemStore) SetPost(post *model.Post) error

SetPost stores the given post.

func (*MemStore) SetPosts

func (s *MemStore) SetPosts(posts []*model.Post) error

SetPosts stores the given posts.

func (*MemStore) SetPreferences

func (s *MemStore) SetPreferences(preferences model.Preferences) error

Preferences stores the preferences for the stored user.

func (*MemStore) SetProfileImage

func (s *MemStore) SetProfileImage(userId string, lastPictureUpdate int) error

SetProfileImage sets as stored the profile image for the given user.

func (*MemStore) SetReaction

func (s *MemStore) SetReaction(reaction *model.Reaction) error

SetReaction stores the given reaction.

func (*MemStore) SetRoles

func (s *MemStore) SetRoles(roles []*model.Role) error

SetRoles stores the given roles.

func (*MemStore) SetServerVersion added in v1.2.0

func (s *MemStore) SetServerVersion(version string) error

SetServerVersion stores the given server version.

func (*MemStore) SetStatus

func (s *MemStore) SetStatus(userId string, status *model.Status) error

SetStatus stores the status for the given userId.

func (*MemStore) SetTeam

func (s *MemStore) SetTeam(team *model.Team) error

SetTeam stores the given team.

func (*MemStore) SetTeamMember

func (s *MemStore) SetTeamMember(teamId string, teamMember *model.TeamMember) error

SetTeamMember stores the given team member.

func (*MemStore) SetTeamMembers

func (s *MemStore) SetTeamMembers(teamId string, teamMembers []*model.TeamMember) error

SetTeamMembers stores the given team members.

func (*MemStore) SetTeams

func (s *MemStore) SetTeams(teams []*model.Team) error

SetTeams stores the given teams.

func (*MemStore) SetThread added in v1.5.0

func (s *MemStore) SetThread(thread *model.ThreadResponse) error

SetThread stores the given thread reponse.

func (*MemStore) SetThreads added in v1.5.0

func (s *MemStore) SetThreads(trs []*model.ThreadResponse) error

SetThreads stores the given thread response as a thread.

func (*MemStore) SetUser

func (s *MemStore) SetUser(user *model.User) error

SetUser stores the given user.

func (*MemStore) SetUsers

func (s *MemStore) SetUsers(users []*model.User) error

SetUsers stores the given users.

func (*MemStore) Status

func (s *MemStore) Status(userId string) (model.Status, error)

Status returns the status for the given userId.

func (*MemStore) Team

func (s *MemStore) Team(teamId string) (*model.Team, error)

Team returns the team for the given teamId.

func (*MemStore) TeamMember

func (s *MemStore) TeamMember(teamId, userId string) (model.TeamMember, error)

TeamMember returns the team member for the given teamId and userId.

func (*MemStore) Teams

func (s *MemStore) Teams() ([]model.Team, error)

Teams returns the teams a user belong to.

func (*MemStore) Thread added in v1.5.0

func (s *MemStore) Thread(threadId string) (*model.ThreadResponse, error)

Thread returns the thread for the given the threadId.

func (*MemStore) ThreadsSorted added in v1.5.0

func (s *MemStore) ThreadsSorted(unreadOnly, asc bool) ([]*model.ThreadResponse, error)

ThreadsSorted returns all threads, sorted by LastReplyAt

func (*MemStore) UpdateChannelBookmark added in v1.23.0

func (s *MemStore) UpdateChannelBookmark(bookmark *model.ChannelBookmarkWithFileInfo) error

UpdateChannelBookmark updates a given bookmark.

func (*MemStore) User

func (s *MemStore) User() (*model.User, error)

User returns the stored user.

func (*MemStore) UserForPost

func (s *MemStore) UserForPost(postId string) (string, error)

UserForPost returns the userId for the user who created the specified post.

func (*MemStore) Username

func (s *MemStore) Username() string

Username returns the username for the stored user.

func (*MemStore) Users added in v1.10.0

func (s *MemStore) Users() ([]model.User, error)

Users returns all users in the store.

func (*MemStore) UsersIdsForPostsIds

func (s *MemStore) UsersIdsForPostsIds(postIds []string) ([]string, error)

UsersIdsForPostsIds returns a list of user ids that created the specified posts.

Jump to

Keyboard shortcuts

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