github.com/gigforks/mattermost-server@v4.9.1-0.20180619094218-800d97fa55d0+incompatible/store/store.go (about) 1 // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package store 5 6 import ( 7 "time" 8 9 "github.com/mattermost/mattermost-server/model" 10 ) 11 12 type StoreResult struct { 13 Data interface{} 14 Err *model.AppError 15 } 16 17 type StoreChannel chan StoreResult 18 19 func Do(f func(result *StoreResult)) StoreChannel { 20 storeChannel := make(StoreChannel, 1) 21 go func() { 22 result := StoreResult{} 23 f(&result) 24 storeChannel <- result 25 close(storeChannel) 26 }() 27 return storeChannel 28 } 29 30 func Must(sc StoreChannel) interface{} { 31 r := <-sc 32 if r.Err != nil { 33 34 time.Sleep(time.Second) 35 panic(r.Err) 36 } 37 38 return r.Data 39 } 40 41 type Store interface { 42 Team() TeamStore 43 Channel() ChannelStore 44 Post() PostStore 45 User() UserStore 46 Audit() AuditStore 47 ClusterDiscovery() ClusterDiscoveryStore 48 Compliance() ComplianceStore 49 Session() SessionStore 50 OAuth() OAuthStore 51 System() SystemStore 52 Webhook() WebhookStore 53 Command() CommandStore 54 CommandWebhook() CommandWebhookStore 55 Preference() PreferenceStore 56 License() LicenseStore 57 Token() TokenStore 58 Emoji() EmojiStore 59 Status() StatusStore 60 FileInfo() FileInfoStore 61 Reaction() ReactionStore 62 Role() RoleStore 63 Job() JobStore 64 UserAccessToken() UserAccessTokenStore 65 ChannelMemberHistory() ChannelMemberHistoryStore 66 Plugin() PluginStore 67 MarkSystemRanUnitTests() 68 Close() 69 DropAllTables() 70 TotalMasterDbConnections() int 71 TotalReadDbConnections() int 72 TotalSearchDbConnections() int 73 } 74 75 type TeamStore interface { 76 Save(team *model.Team) StoreChannel 77 Update(team *model.Team) StoreChannel 78 UpdateDisplayName(name string, teamId string) StoreChannel 79 Get(id string) StoreChannel 80 GetByName(name string) StoreChannel 81 SearchByName(name string) StoreChannel 82 SearchAll(term string) StoreChannel 83 SearchOpen(term string) StoreChannel 84 GetAll() StoreChannel 85 GetAllPage(offset int, limit int) StoreChannel 86 GetAllTeamListing() StoreChannel 87 GetAllTeamPageListing(offset int, limit int) StoreChannel 88 GetTeamsByUserId(userId string) StoreChannel 89 GetByInviteId(inviteId string) StoreChannel 90 PermanentDelete(teamId string) StoreChannel 91 AnalyticsTeamCount() StoreChannel 92 SaveMember(member *model.TeamMember, maxUsersPerTeam int) StoreChannel 93 UpdateMember(member *model.TeamMember) StoreChannel 94 GetMember(teamId string, userId string) StoreChannel 95 GetMembers(teamId string, offset int, limit int) StoreChannel 96 GetMembersByIds(teamId string, userIds []string) StoreChannel 97 GetTotalMemberCount(teamId string) StoreChannel 98 GetActiveMemberCount(teamId string) StoreChannel 99 GetTeamsForUser(userId string) StoreChannel 100 GetChannelUnreadsForAllTeams(excludeTeamId, userId string) StoreChannel 101 GetChannelUnreadsForTeam(teamId, userId string) StoreChannel 102 RemoveMember(teamId string, userId string) StoreChannel 103 RemoveAllMembersByTeam(teamId string) StoreChannel 104 RemoveAllMembersByUser(userId string) StoreChannel 105 UpdateLastTeamIconUpdate(teamId string, curTime int64) StoreChannel 106 } 107 108 type ChannelStore interface { 109 Save(channel *model.Channel, maxChannelsPerTeam int64) StoreChannel 110 CreateDirectChannel(userId string, otherUserId string) StoreChannel 111 SaveDirectChannel(channel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) StoreChannel 112 Update(channel *model.Channel) StoreChannel 113 Get(id string, allowFromCache bool) StoreChannel 114 InvalidateChannel(id string) 115 InvalidateChannelByName(teamId, name string) 116 GetFromMaster(id string) StoreChannel 117 Delete(channelId string, time int64) StoreChannel 118 Restore(channelId string, time int64) StoreChannel 119 SetDeleteAt(channelId string, deleteAt int64, updateAt int64) StoreChannel 120 PermanentDeleteByTeam(teamId string) StoreChannel 121 PermanentDelete(channelId string) StoreChannel 122 GetByName(team_id string, name string, allowFromCache bool) StoreChannel 123 GetByNames(team_id string, names []string, allowFromCache bool) StoreChannel 124 GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) StoreChannel 125 GetDeletedByName(team_id string, name string) StoreChannel 126 GetDeleted(team_id string, offset int, limit int) StoreChannel 127 GetChannels(teamId string, userId string) StoreChannel 128 GetMoreChannels(teamId string, userId string, offset int, limit int) StoreChannel 129 GetPublicChannelsForTeam(teamId string, offset int, limit int) StoreChannel 130 GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) StoreChannel 131 GetChannelCounts(teamId string, userId string) StoreChannel 132 GetTeamChannels(teamId string) StoreChannel 133 GetAll(teamId string) StoreChannel 134 GetForPost(postId string) StoreChannel 135 SaveMember(member *model.ChannelMember) StoreChannel 136 UpdateMember(member *model.ChannelMember) StoreChannel 137 GetMembers(channelId string, offset, limit int) StoreChannel 138 GetMember(channelId string, userId string) StoreChannel 139 GetAllChannelMembersForUser(userId string, allowFromCache bool) StoreChannel 140 InvalidateAllChannelMembersForUser(userId string) 141 IsUserInChannelUseCache(userId string, channelId string) bool 142 GetAllChannelMembersNotifyPropsForChannel(channelId string, allowFromCache bool) StoreChannel 143 InvalidateCacheForChannelMembersNotifyProps(channelId string) 144 GetMemberForPost(postId string, userId string) StoreChannel 145 InvalidateMemberCount(channelId string) 146 GetMemberCountFromCache(channelId string) int64 147 GetMemberCount(channelId string, allowFromCache bool) StoreChannel 148 GetPinnedPosts(channelId string) StoreChannel 149 RemoveMember(channelId string, userId string) StoreChannel 150 PermanentDeleteMembersByUser(userId string) StoreChannel 151 PermanentDeleteMembersByChannel(channelId string) StoreChannel 152 UpdateLastViewedAt(channelIds []string, userId string) StoreChannel 153 IncrementMentionCount(channelId string, userId string) StoreChannel 154 AnalyticsTypeCount(teamId string, channelType string) StoreChannel 155 GetMembersForUser(teamId string, userId string) StoreChannel 156 AutocompleteInTeam(teamId string, term string) StoreChannel 157 SearchInTeam(teamId string, term string) StoreChannel 158 SearchMore(userId string, teamId string, term string) StoreChannel 159 GetMembersByIds(channelId string, userIds []string) StoreChannel 160 AnalyticsDeletedTypeCount(teamId string, channelType string) StoreChannel 161 GetChannelUnread(channelId, userId string) StoreChannel 162 ClearCaches() 163 } 164 165 type ChannelMemberHistoryStore interface { 166 LogJoinEvent(userId string, channelId string, joinTime int64) StoreChannel 167 LogLeaveEvent(userId string, channelId string, leaveTime int64) StoreChannel 168 GetUsersInChannelDuring(startTime int64, endTime int64, channelId string) StoreChannel 169 PermanentDeleteBatch(endTime int64, limit int64) StoreChannel 170 } 171 172 type PostStore interface { 173 Save(post *model.Post) StoreChannel 174 Update(newPost *model.Post, oldPost *model.Post) StoreChannel 175 Get(id string) StoreChannel 176 GetSingle(id string) StoreChannel 177 Delete(postId string, time int64) StoreChannel 178 PermanentDeleteByUser(userId string) StoreChannel 179 PermanentDeleteByChannel(channelId string) StoreChannel 180 GetPosts(channelId string, offset int, limit int, allowFromCache bool) StoreChannel 181 GetFlaggedPosts(userId string, offset int, limit int) StoreChannel 182 GetFlaggedPostsForTeam(userId, teamId string, offset int, limit int) StoreChannel 183 GetFlaggedPostsForChannel(userId, channelId string, offset int, limit int) StoreChannel 184 GetPostsBefore(channelId string, postId string, numPosts int, offset int) StoreChannel 185 GetPostsAfter(channelId string, postId string, numPosts int, offset int) StoreChannel 186 GetPostsSince(channelId string, time int64, allowFromCache bool) StoreChannel 187 GetEtag(channelId string, allowFromCache bool) StoreChannel 188 Search(teamId string, userId string, params *model.SearchParams) StoreChannel 189 AnalyticsUserCountsWithPostsByDay(teamId string) StoreChannel 190 AnalyticsPostCountsByDay(teamId string) StoreChannel 191 AnalyticsPostCount(teamId string, mustHaveFile bool, mustHaveHashtag bool) StoreChannel 192 ClearCaches() 193 InvalidateLastPostTimeCache(channelId string) 194 GetPostsCreatedAt(channelId string, time int64) StoreChannel 195 Overwrite(post *model.Post) StoreChannel 196 GetPostsByIds(postIds []string) StoreChannel 197 GetPostsBatchForIndexing(startTime int64, endTime int64, limit int) StoreChannel 198 PermanentDeleteBatch(endTime int64, limit int64) StoreChannel 199 GetOldest() StoreChannel 200 GetMaxPostSize() StoreChannel 201 } 202 203 type UserStore interface { 204 Save(user *model.User) StoreChannel 205 Update(user *model.User, allowRoleUpdate bool) StoreChannel 206 UpdateLastPictureUpdate(userId string) StoreChannel 207 UpdateUpdateAt(userId string) StoreChannel 208 UpdatePassword(userId, newPassword string) StoreChannel 209 UpdateAuthData(userId string, service string, authData *string, email string, resetMfa bool) StoreChannel 210 UpdateMfaSecret(userId, secret string) StoreChannel 211 UpdateMfaActive(userId string, active bool) StoreChannel 212 Get(id string) StoreChannel 213 GetAll() StoreChannel 214 ClearCaches() 215 InvalidateProfilesInChannelCacheByUser(userId string) 216 InvalidateProfilesInChannelCache(channelId string) 217 GetProfilesInChannel(channelId string, offset int, limit int) StoreChannel 218 GetProfilesInChannelByStatus(channelId string, offset int, limit int) StoreChannel 219 GetAllProfilesInChannel(channelId string, allowFromCache bool) StoreChannel 220 GetProfilesNotInChannel(teamId string, channelId string, offset int, limit int) StoreChannel 221 GetProfilesWithoutTeam(offset int, limit int) StoreChannel 222 GetProfilesByUsernames(usernames []string, teamId string) StoreChannel 223 GetAllProfiles(offset int, limit int) StoreChannel 224 GetProfiles(teamId string, offset int, limit int) StoreChannel 225 GetProfileByIds(userId []string, allowFromCache bool) StoreChannel 226 InvalidatProfileCacheForUser(userId string) 227 GetByEmail(email string) StoreChannel 228 GetByAuth(authData *string, authService string) StoreChannel 229 GetAllUsingAuthService(authService string) StoreChannel 230 GetByUsername(username string) StoreChannel 231 GetForLogin(loginId string, allowSignInWithUsername, allowSignInWithEmail bool) StoreChannel 232 VerifyEmail(userId string) StoreChannel 233 GetEtagForAllProfiles() StoreChannel 234 GetEtagForProfiles(teamId string) StoreChannel 235 UpdateFailedPasswordAttempts(userId string, attempts int) StoreChannel 236 GetTotalUsersCount() StoreChannel 237 GetSystemAdminProfiles() StoreChannel 238 PermanentDelete(userId string) StoreChannel 239 AnalyticsUniqueUserCount(teamId string) StoreChannel 240 AnalyticsActiveCount(time int64) StoreChannel 241 GetUnreadCount(userId string) StoreChannel 242 GetUnreadCountForChannel(userId string, channelId string) StoreChannel 243 GetRecentlyActiveUsersForTeam(teamId string, offset, limit int) StoreChannel 244 GetNewUsersForTeam(teamId string, offset, limit int) StoreChannel 245 Search(teamId string, term string, options map[string]bool) StoreChannel 246 SearchNotInTeam(notInTeamId string, term string, options map[string]bool) StoreChannel 247 SearchInChannel(channelId string, term string, options map[string]bool) StoreChannel 248 SearchNotInChannel(teamId string, channelId string, term string, options map[string]bool) StoreChannel 249 SearchWithoutTeam(term string, options map[string]bool) StoreChannel 250 AnalyticsGetInactiveUsersCount() StoreChannel 251 AnalyticsGetSystemAdminCount() StoreChannel 252 GetProfilesNotInTeam(teamId string, offset int, limit int) StoreChannel 253 GetEtagForProfilesNotInTeam(teamId string) StoreChannel 254 } 255 256 type SessionStore interface { 257 Save(session *model.Session) StoreChannel 258 Get(sessionIdOrToken string) StoreChannel 259 GetSessions(userId string) StoreChannel 260 GetSessionsWithActiveDeviceIds(userId string) StoreChannel 261 Remove(sessionIdOrToken string) StoreChannel 262 RemoveAllSessions() StoreChannel 263 PermanentDeleteSessionsByUser(teamId string) StoreChannel 264 UpdateLastActivityAt(sessionId string, time int64) StoreChannel 265 UpdateRoles(userId string, roles string) StoreChannel 266 UpdateDeviceId(id string, deviceId string, expiresAt int64) StoreChannel 267 AnalyticsSessionCount() StoreChannel 268 Cleanup(expiryTime int64, batchSize int64) 269 } 270 271 type AuditStore interface { 272 Save(audit *model.Audit) StoreChannel 273 Get(user_id string, offset int, limit int) StoreChannel 274 PermanentDeleteByUser(userId string) StoreChannel 275 PermanentDeleteBatch(endTime int64, limit int64) StoreChannel 276 } 277 278 type ClusterDiscoveryStore interface { 279 Save(discovery *model.ClusterDiscovery) StoreChannel 280 Delete(discovery *model.ClusterDiscovery) StoreChannel 281 Exists(discovery *model.ClusterDiscovery) StoreChannel 282 GetAll(discoveryType, clusterName string) StoreChannel 283 SetLastPingAt(discovery *model.ClusterDiscovery) StoreChannel 284 Cleanup() StoreChannel 285 } 286 287 type ComplianceStore interface { 288 Save(compliance *model.Compliance) StoreChannel 289 Update(compliance *model.Compliance) StoreChannel 290 Get(id string) StoreChannel 291 GetAll(offset, limit int) StoreChannel 292 ComplianceExport(compliance *model.Compliance) StoreChannel 293 MessageExport(after int64, limit int) StoreChannel 294 } 295 296 type OAuthStore interface { 297 SaveApp(app *model.OAuthApp) StoreChannel 298 UpdateApp(app *model.OAuthApp) StoreChannel 299 GetApp(id string) StoreChannel 300 GetAppByUser(userId string, offset, limit int) StoreChannel 301 GetApps(offset, limit int) StoreChannel 302 GetAuthorizedApps(userId string, offset, limit int) StoreChannel 303 DeleteApp(id string) StoreChannel 304 SaveAuthData(authData *model.AuthData) StoreChannel 305 GetAuthData(code string) StoreChannel 306 RemoveAuthData(code string) StoreChannel 307 PermanentDeleteAuthDataByUser(userId string) StoreChannel 308 SaveAccessData(accessData *model.AccessData) StoreChannel 309 UpdateAccessData(accessData *model.AccessData) StoreChannel 310 GetAccessData(token string) StoreChannel 311 GetAccessDataByUserForApp(userId, clientId string) StoreChannel 312 GetAccessDataByRefreshToken(token string) StoreChannel 313 GetPreviousAccessData(userId, clientId string) StoreChannel 314 RemoveAccessData(token string) StoreChannel 315 } 316 317 type SystemStore interface { 318 Save(system *model.System) StoreChannel 319 SaveOrUpdate(system *model.System) StoreChannel 320 Update(system *model.System) StoreChannel 321 Get() StoreChannel 322 GetByName(name string) StoreChannel 323 PermanentDeleteByName(name string) StoreChannel 324 } 325 326 type WebhookStore interface { 327 SaveIncoming(webhook *model.IncomingWebhook) StoreChannel 328 GetIncoming(id string, allowFromCache bool) StoreChannel 329 GetIncomingList(offset, limit int) StoreChannel 330 GetIncomingByTeam(teamId string, offset, limit int) StoreChannel 331 UpdateIncoming(webhook *model.IncomingWebhook) StoreChannel 332 GetIncomingByChannel(channelId string) StoreChannel 333 DeleteIncoming(webhookId string, time int64) StoreChannel 334 PermanentDeleteIncomingByChannel(channelId string) StoreChannel 335 PermanentDeleteIncomingByUser(userId string) StoreChannel 336 337 SaveOutgoing(webhook *model.OutgoingWebhook) StoreChannel 338 GetOutgoing(id string) StoreChannel 339 GetOutgoingList(offset, limit int) StoreChannel 340 GetOutgoingByChannel(channelId string, offset, limit int) StoreChannel 341 GetOutgoingByTeam(teamId string, offset, limit int) StoreChannel 342 DeleteOutgoing(webhookId string, time int64) StoreChannel 343 PermanentDeleteOutgoingByChannel(channelId string) StoreChannel 344 PermanentDeleteOutgoingByUser(userId string) StoreChannel 345 UpdateOutgoing(hook *model.OutgoingWebhook) StoreChannel 346 347 AnalyticsIncomingCount(teamId string) StoreChannel 348 AnalyticsOutgoingCount(teamId string) StoreChannel 349 InvalidateWebhookCache(webhook string) 350 ClearCaches() 351 } 352 353 type CommandStore interface { 354 Save(webhook *model.Command) StoreChannel 355 Get(id string) StoreChannel 356 GetByTeam(teamId string) StoreChannel 357 GetByTrigger(teamId string, trigger string) StoreChannel 358 Delete(commandId string, time int64) StoreChannel 359 PermanentDeleteByTeam(teamId string) StoreChannel 360 PermanentDeleteByUser(userId string) StoreChannel 361 Update(hook *model.Command) StoreChannel 362 AnalyticsCommandCount(teamId string) StoreChannel 363 } 364 365 type CommandWebhookStore interface { 366 Save(webhook *model.CommandWebhook) StoreChannel 367 Get(id string) StoreChannel 368 TryUse(id string, limit int) StoreChannel 369 Cleanup() 370 } 371 372 type PreferenceStore interface { 373 Save(preferences *model.Preferences) StoreChannel 374 Get(userId string, category string, name string) StoreChannel 375 GetCategory(userId string, category string) StoreChannel 376 GetAll(userId string) StoreChannel 377 Delete(userId, category, name string) StoreChannel 378 DeleteCategory(userId string, category string) StoreChannel 379 DeleteCategoryAndName(category string, name string) StoreChannel 380 PermanentDeleteByUser(userId string) StoreChannel 381 IsFeatureEnabled(feature, userId string) StoreChannel 382 CleanupFlagsBatch(limit int64) StoreChannel 383 } 384 385 type LicenseStore interface { 386 Save(license *model.LicenseRecord) StoreChannel 387 Get(id string) StoreChannel 388 } 389 390 type TokenStore interface { 391 Save(recovery *model.Token) StoreChannel 392 Delete(token string) StoreChannel 393 GetByToken(token string) StoreChannel 394 Cleanup() 395 } 396 397 type EmojiStore interface { 398 Save(emoji *model.Emoji) StoreChannel 399 Get(id string, allowFromCache bool) StoreChannel 400 GetByName(name string) StoreChannel 401 GetList(offset, limit int, sort string) StoreChannel 402 Delete(id string, time int64) StoreChannel 403 Search(name string, prefixOnly bool, limit int) StoreChannel 404 } 405 406 type StatusStore interface { 407 SaveOrUpdate(status *model.Status) StoreChannel 408 Get(userId string) StoreChannel 409 GetByIds(userIds []string) StoreChannel 410 GetOnlineAway() StoreChannel 411 GetOnline() StoreChannel 412 GetAllFromTeam(teamId string) StoreChannel 413 ResetAll() StoreChannel 414 GetTotalActiveUsersCount() StoreChannel 415 UpdateLastActivityAt(userId string, lastActivityAt int64) StoreChannel 416 } 417 418 type FileInfoStore interface { 419 Save(info *model.FileInfo) StoreChannel 420 Get(id string) StoreChannel 421 GetByPath(path string) StoreChannel 422 GetForPost(postId string, readFromMaster bool, allowFromCache bool) StoreChannel 423 InvalidateFileInfosForPostCache(postId string) 424 AttachToPost(fileId string, postId string) StoreChannel 425 DeleteForPost(postId string) StoreChannel 426 PermanentDelete(fileId string) StoreChannel 427 PermanentDeleteBatch(endTime int64, limit int64) StoreChannel 428 ClearCaches() 429 } 430 431 type ReactionStore interface { 432 Save(reaction *model.Reaction) StoreChannel 433 Delete(reaction *model.Reaction) StoreChannel 434 GetForPost(postId string, allowFromCache bool) StoreChannel 435 DeleteAllWithEmojiName(emojiName string) StoreChannel 436 PermanentDeleteBatch(endTime int64, limit int64) StoreChannel 437 } 438 439 type JobStore interface { 440 Save(job *model.Job) StoreChannel 441 UpdateOptimistically(job *model.Job, currentStatus string) StoreChannel 442 UpdateStatus(id string, status string) StoreChannel 443 UpdateStatusOptimistically(id string, currentStatus string, newStatus string) StoreChannel 444 Get(id string) StoreChannel 445 GetAllPage(offset int, limit int) StoreChannel 446 GetAllByType(jobType string) StoreChannel 447 GetAllByTypePage(jobType string, offset int, limit int) StoreChannel 448 GetAllByStatus(status string) StoreChannel 449 GetNewestJobByStatusAndType(status string, jobType string) StoreChannel 450 GetCountByStatusAndType(status string, jobType string) StoreChannel 451 Delete(id string) StoreChannel 452 } 453 454 type UserAccessTokenStore interface { 455 Save(token *model.UserAccessToken) StoreChannel 456 Delete(tokenId string) StoreChannel 457 DeleteAllForUser(userId string) StoreChannel 458 Get(tokenId string) StoreChannel 459 GetAll(offset int, limit int) StoreChannel 460 GetByToken(tokenString string) StoreChannel 461 GetByUser(userId string, page, perPage int) StoreChannel 462 Search(term string) StoreChannel 463 UpdateTokenEnable(tokenId string) StoreChannel 464 UpdateTokenDisable(tokenId string) StoreChannel 465 } 466 467 type PluginStore interface { 468 SaveOrUpdate(keyVal *model.PluginKeyValue) StoreChannel 469 Get(pluginId, key string) StoreChannel 470 Delete(pluginId, key string) StoreChannel 471 } 472 473 type RoleStore interface { 474 Save(role *model.Role) StoreChannel 475 Get(roleId string) StoreChannel 476 GetByName(name string) StoreChannel 477 GetByNames(names []string) StoreChannel 478 PermanentDeleteAll() StoreChannel 479 }