forked from mattermost/mattermost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.go
370 lines (342 loc) · 15.1 KB
/
store.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package store
import (
"time"
l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/model"
)
type StoreResult struct {
Data interface{}
Err *model.AppError
}
type StoreChannel chan StoreResult
func Must(sc StoreChannel) interface{} {
r := <-sc
if r.Err != nil {
l4g.Close()
time.Sleep(time.Second)
panic(r.Err)
}
return r.Data
}
type Store interface {
Team() TeamStore
Channel() ChannelStore
Post() PostStore
User() UserStore
Audit() AuditStore
Compliance() ComplianceStore
Session() SessionStore
OAuth() OAuthStore
System() SystemStore
Webhook() WebhookStore
Command() CommandStore
Preference() PreferenceStore
License() LicenseStore
Token() TokenStore
Emoji() EmojiStore
Status() StatusStore
FileInfo() FileInfoStore
Reaction() ReactionStore
MarkSystemRanUnitTests()
Close()
DropAllTables()
TotalMasterDbConnections() int
TotalReadDbConnections() int
TotalSearchDbConnections() int
}
type TeamStore interface {
Save(team *model.Team) StoreChannel
Update(team *model.Team) StoreChannel
UpdateDisplayName(name string, teamId string) StoreChannel
Get(id string) StoreChannel
GetByName(name string) StoreChannel
SearchByName(name string) StoreChannel
SearchAll(term string) StoreChannel
SearchOpen(term string) StoreChannel
GetAll() StoreChannel
GetAllPage(offset int, limit int) StoreChannel
GetAllTeamListing() StoreChannel
GetAllTeamPageListing(offset int, limit int) StoreChannel
GetTeamsByUserId(userId string) StoreChannel
GetByInviteId(inviteId string) StoreChannel
PermanentDelete(teamId string) StoreChannel
AnalyticsTeamCount() StoreChannel
SaveMember(member *model.TeamMember) StoreChannel
UpdateMember(member *model.TeamMember) StoreChannel
GetMember(teamId string, userId string) StoreChannel
GetMembers(teamId string, offset int, limit int) StoreChannel
GetMembersByIds(teamId string, userIds []string) StoreChannel
GetTotalMemberCount(teamId string) StoreChannel
GetActiveMemberCount(teamId string) StoreChannel
GetTeamsForUser(userId string) StoreChannel
GetChannelUnreadsForAllTeams(excludeTeamId, userId string) StoreChannel
GetChannelUnreadsForTeam(teamId, userId string) StoreChannel
RemoveMember(teamId string, userId string) StoreChannel
RemoveAllMembersByTeam(teamId string) StoreChannel
RemoveAllMembersByUser(userId string) StoreChannel
}
type ChannelStore interface {
Save(channel *model.Channel) StoreChannel
CreateDirectChannel(userId string, otherUserId string) StoreChannel
SaveDirectChannel(channel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) StoreChannel
Update(channel *model.Channel) StoreChannel
Get(id string, allowFromCache bool) StoreChannel
InvalidateChannel(id string)
InvalidateChannelByName(teamId, name string)
GetFromMaster(id string) StoreChannel
Delete(channelId string, time int64) StoreChannel
SetDeleteAt(channelId string, deleteAt int64, updateAt int64) StoreChannel
PermanentDeleteByTeam(teamId string) StoreChannel
PermanentDelete(channelId string) StoreChannel
GetByName(team_id string, name string, allowFromCache bool) StoreChannel
GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) StoreChannel
GetDeletedByName(team_id string, name string) StoreChannel
GetChannels(teamId string, userId string) StoreChannel
GetMoreChannels(teamId string, userId string, offset int, limit int) StoreChannel
GetPublicChannelsForTeam(teamId string, offset int, limit int) StoreChannel
GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) StoreChannel
GetChannelCounts(teamId string, userId string) StoreChannel
GetTeamChannels(teamId string) StoreChannel
GetAll(teamId string) StoreChannel
GetForPost(postId string) StoreChannel
SaveMember(member *model.ChannelMember) StoreChannel
UpdateMember(member *model.ChannelMember) StoreChannel
GetMembers(channelId string, offset, limit int) StoreChannel
GetMember(channelId string, userId string) StoreChannel
GetAllChannelMembersForUser(userId string, allowFromCache bool) StoreChannel
InvalidateAllChannelMembersForUser(userId string)
IsUserInChannelUseCache(userId string, channelId string) bool
GetAllChannelMembersNotifyPropsForChannel(channelId string, allowFromCache bool) StoreChannel
InvalidateCacheForChannelMembersNotifyProps(channelId string)
GetMemberForPost(postId string, userId string) StoreChannel
InvalidateMemberCount(channelId string)
GetMemberCountFromCache(channelId string) int64
GetMemberCount(channelId string, allowFromCache bool) StoreChannel
GetPinnedPosts(channelId string) StoreChannel
RemoveMember(channelId string, userId string) StoreChannel
PermanentDeleteMembersByUser(userId string) StoreChannel
PermanentDeleteMembersByChannel(channelId string) StoreChannel
UpdateLastViewedAt(channelIds []string, userId string) StoreChannel
IncrementMentionCount(channelId string, userId string) StoreChannel
AnalyticsTypeCount(teamId string, channelType string) StoreChannel
ExtraUpdateByUser(userId string, time int64) StoreChannel
GetMembersForUser(teamId string, userId string) StoreChannel
SearchInTeam(teamId string, term string) StoreChannel
SearchMore(userId string, teamId string, term string) StoreChannel
GetMembersByIds(channelId string, userIds []string) StoreChannel
AnalyticsDeletedTypeCount(teamId string, channelType string) StoreChannel
GetChannelUnread(channelId, userId string) StoreChannel
}
type PostStore interface {
Save(post *model.Post) StoreChannel
Update(newPost *model.Post, oldPost *model.Post) StoreChannel
Get(id string) StoreChannel
GetSingle(id string) StoreChannel
Delete(postId string, time int64) StoreChannel
PermanentDeleteByUser(userId string) StoreChannel
PermanentDeleteByChannel(channelId string) StoreChannel
GetPosts(channelId string, offset int, limit int, allowFromCache bool) StoreChannel
GetFlaggedPosts(userId string, offset int, limit int) StoreChannel
GetFlaggedPostsForTeam(userId, teamId string, offset int, limit int) StoreChannel
GetFlaggedPostsForChannel(userId, channelId string, offset int, limit int) StoreChannel
GetPostsBefore(channelId string, postId string, numPosts int, offset int) StoreChannel
GetPostsAfter(channelId string, postId string, numPosts int, offset int) StoreChannel
GetPostsSince(channelId string, time int64, allowFromCache bool) StoreChannel
GetEtag(channelId string, allowFromCache bool) StoreChannel
Search(teamId string, userId string, params *model.SearchParams) StoreChannel
AnalyticsUserCountsWithPostsByDay(teamId string) StoreChannel
AnalyticsPostCountsByDay(teamId string) StoreChannel
AnalyticsPostCount(teamId string, mustHaveFile bool, mustHaveHashtag bool) StoreChannel
InvalidateLastPostTimeCache(channelId string)
GetPostsCreatedAt(channelId string, time int64) StoreChannel
Overwrite(post *model.Post) StoreChannel
}
type UserStore interface {
Save(user *model.User) StoreChannel
Update(user *model.User, allowRoleUpdate bool) StoreChannel
UpdateLastPictureUpdate(userId string) StoreChannel
UpdateUpdateAt(userId string) StoreChannel
UpdatePassword(userId, newPassword string) StoreChannel
UpdateAuthData(userId string, service string, authData *string, email string, resetMfa bool) StoreChannel
UpdateMfaSecret(userId, secret string) StoreChannel
UpdateMfaActive(userId string, active bool) StoreChannel
Get(id string) StoreChannel
GetAll() StoreChannel
InvalidateProfilesInChannelCacheByUser(userId string)
InvalidateProfilesInChannelCache(channelId string)
GetProfilesInChannel(channelId string, offset int, limit int) StoreChannel
GetAllProfilesInChannel(channelId string, allowFromCache bool) StoreChannel
GetProfilesNotInChannel(teamId string, channelId string, offset int, limit int) StoreChannel
GetProfilesWithoutTeam(offset int, limit int) StoreChannel
GetProfilesByUsernames(usernames []string, teamId string) StoreChannel
GetAllProfiles(offset int, limit int) StoreChannel
GetProfiles(teamId string, offset int, limit int) StoreChannel
GetProfileByIds(userId []string, allowFromCache bool) StoreChannel
InvalidatProfileCacheForUser(userId string)
GetByEmail(email string) StoreChannel
GetByAuth(authData *string, authService string) StoreChannel
GetAllUsingAuthService(authService string) StoreChannel
GetByUsername(username string) StoreChannel
GetForLogin(loginId string, allowSignInWithUsername, allowSignInWithEmail, ldapEnabled bool) StoreChannel
VerifyEmail(userId string) StoreChannel
GetEtagForAllProfiles() StoreChannel
GetEtagForProfiles(teamId string) StoreChannel
UpdateFailedPasswordAttempts(userId string, attempts int) StoreChannel
GetTotalUsersCount() StoreChannel
GetSystemAdminProfiles() StoreChannel
PermanentDelete(userId string) StoreChannel
AnalyticsUniqueUserCount(teamId string) StoreChannel
AnalyticsActiveCount(time int64) StoreChannel
GetUnreadCount(userId string) StoreChannel
GetUnreadCountForChannel(userId string, channelId string) StoreChannel
GetRecentlyActiveUsersForTeam(teamId string) StoreChannel
Search(teamId string, term string, options map[string]bool) StoreChannel
SearchNotInTeam(notInTeamId string, term string, options map[string]bool) StoreChannel
SearchInChannel(channelId string, term string, options map[string]bool) StoreChannel
SearchNotInChannel(teamId string, channelId string, term string, options map[string]bool) StoreChannel
SearchWithoutTeam(term string, options map[string]bool) StoreChannel
AnalyticsGetInactiveUsersCount() StoreChannel
AnalyticsGetSystemAdminCount() StoreChannel
GetProfilesNotInTeam(teamId string, offset int, limit int) StoreChannel
GetEtagForProfilesNotInTeam(teamId string) StoreChannel
}
type SessionStore interface {
Save(session *model.Session) StoreChannel
Get(sessionIdOrToken string) StoreChannel
GetSessions(userId string) StoreChannel
GetSessionsWithActiveDeviceIds(userId string) StoreChannel
Remove(sessionIdOrToken string) StoreChannel
RemoveAllSessions() StoreChannel
PermanentDeleteSessionsByUser(teamId string) StoreChannel
UpdateLastActivityAt(sessionId string, time int64) StoreChannel
UpdateRoles(userId string, roles string) StoreChannel
UpdateDeviceId(id string, deviceId string, expiresAt int64) StoreChannel
AnalyticsSessionCount() StoreChannel
}
type AuditStore interface {
Save(audit *model.Audit) StoreChannel
Get(user_id string, offset int, limit int) StoreChannel
PermanentDeleteByUser(userId string) StoreChannel
}
type ComplianceStore interface {
Save(compliance *model.Compliance) StoreChannel
Update(compliance *model.Compliance) StoreChannel
Get(id string) StoreChannel
GetAll(offset, limit int) StoreChannel
ComplianceExport(compliance *model.Compliance) StoreChannel
}
type OAuthStore interface {
SaveApp(app *model.OAuthApp) StoreChannel
UpdateApp(app *model.OAuthApp) StoreChannel
GetApp(id string) StoreChannel
GetAppByUser(userId string, offset, limit int) StoreChannel
GetApps(offset, limit int) StoreChannel
GetAuthorizedApps(userId string, offset, limit int) StoreChannel
DeleteApp(id string) StoreChannel
SaveAuthData(authData *model.AuthData) StoreChannel
GetAuthData(code string) StoreChannel
RemoveAuthData(code string) StoreChannel
PermanentDeleteAuthDataByUser(userId string) StoreChannel
SaveAccessData(accessData *model.AccessData) StoreChannel
UpdateAccessData(accessData *model.AccessData) StoreChannel
GetAccessData(token string) StoreChannel
GetAccessDataByUserForApp(userId, clientId string) StoreChannel
GetAccessDataByRefreshToken(token string) StoreChannel
GetPreviousAccessData(userId, clientId string) StoreChannel
RemoveAccessData(token string) StoreChannel
}
type SystemStore interface {
Save(system *model.System) StoreChannel
SaveOrUpdate(system *model.System) StoreChannel
Update(system *model.System) StoreChannel
Get() StoreChannel
GetByName(name string) StoreChannel
}
type WebhookStore interface {
SaveIncoming(webhook *model.IncomingWebhook) StoreChannel
GetIncoming(id string, allowFromCache bool) StoreChannel
GetIncomingList(offset, limit int) StoreChannel
GetIncomingByTeam(teamId string, offset, limit int) StoreChannel
UpdateIncoming(webhook *model.IncomingWebhook) StoreChannel
GetIncomingByChannel(channelId string) StoreChannel
DeleteIncoming(webhookId string, time int64) StoreChannel
PermanentDeleteIncomingByUser(userId string) StoreChannel
SaveOutgoing(webhook *model.OutgoingWebhook) StoreChannel
GetOutgoing(id string) StoreChannel
GetOutgoingList(offset, limit int) StoreChannel
GetOutgoingByChannel(channelId string, offset, limit int) StoreChannel
GetOutgoingByTeam(teamId string, offset, limit int) StoreChannel
DeleteOutgoing(webhookId string, time int64) StoreChannel
PermanentDeleteOutgoingByUser(userId string) StoreChannel
UpdateOutgoing(hook *model.OutgoingWebhook) StoreChannel
AnalyticsIncomingCount(teamId string) StoreChannel
AnalyticsOutgoingCount(teamId string) StoreChannel
InvalidateWebhookCache(webhook string)
}
type CommandStore interface {
Save(webhook *model.Command) StoreChannel
Get(id string) StoreChannel
GetByTeam(teamId string) StoreChannel
Delete(commandId string, time int64) StoreChannel
PermanentDeleteByUser(userId string) StoreChannel
Update(hook *model.Command) StoreChannel
AnalyticsCommandCount(teamId string) StoreChannel
}
type PreferenceStore interface {
Save(preferences *model.Preferences) StoreChannel
Get(userId string, category string, name string) StoreChannel
GetCategory(userId string, category string) StoreChannel
GetAll(userId string) StoreChannel
Delete(userId, category, name string) StoreChannel
DeleteCategory(userId string, category string) StoreChannel
DeleteCategoryAndName(category string, name string) StoreChannel
PermanentDeleteByUser(userId string) StoreChannel
IsFeatureEnabled(feature, userId string) StoreChannel
}
type LicenseStore interface {
Save(license *model.LicenseRecord) StoreChannel
Get(id string) StoreChannel
}
type TokenStore interface {
Save(recovery *model.Token) StoreChannel
Delete(token string) StoreChannel
GetByToken(token string) StoreChannel
Cleanup()
}
type EmojiStore interface {
Save(emoji *model.Emoji) StoreChannel
Get(id string, allowFromCache bool) StoreChannel
GetByName(name string) StoreChannel
GetAll() StoreChannel
Delete(id string, time int64) StoreChannel
}
type StatusStore interface {
SaveOrUpdate(status *model.Status) StoreChannel
Get(userId string) StoreChannel
GetByIds(userIds []string) StoreChannel
GetOnlineAway() StoreChannel
GetOnline() StoreChannel
GetAllFromTeam(teamId string) StoreChannel
ResetAll() StoreChannel
GetTotalActiveUsersCount() StoreChannel
UpdateLastActivityAt(userId string, lastActivityAt int64) StoreChannel
}
type FileInfoStore interface {
Save(info *model.FileInfo) StoreChannel
Get(id string) StoreChannel
GetByPath(path string) StoreChannel
GetForPost(postId string, readFromMaster bool, allowFromCache bool) StoreChannel
InvalidateFileInfosForPostCache(postId string)
AttachToPost(fileId string, postId string) StoreChannel
DeleteForPost(postId string) StoreChannel
}
type ReactionStore interface {
Save(reaction *model.Reaction) StoreChannel
Delete(reaction *model.Reaction) StoreChannel
InvalidateCacheForPost(postId string)
InvalidateCache()
GetForPost(postId string, allowFromCache bool) StoreChannel
DeleteAllWithEmojiName(emojiName string) StoreChannel
}