github.com/wgh-/mattermost-server@v4.8.0-rc2+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 l4g "github.com/alecthomas/log4go" 10 11 "github.com/mattermost/mattermost-server/model" 12 ) 13 14 type StoreResult struct { 15 Data interface{} 16 Err *model.AppError 17 } 18 19 type StoreChannel chan StoreResult 20 21 func Do(f func(result *StoreResult)) StoreChannel { 22 storeChannel := make(StoreChannel, 1) 23 go func() { 24 result := StoreResult{} 25 f(&result) 26 storeChannel <- result 27 close(storeChannel) 28 }() 29 return storeChannel 30 } 31 32 func Must(sc StoreChannel) interface{} { 33 r := <-sc 34 if r.Err != nil { 35 l4g.Close() 36 time.Sleep(time.Second) 37 panic(r.Err) 38 } 39 40 return r.Data 41 } 42 43 type Store interface { 44 Team() TeamStore 45 Channel() ChannelStore 46 Post() PostStore 47 User() UserStore 48 Audit() AuditStore 49 ClusterDiscovery() ClusterDiscoveryStore 50 Compliance() ComplianceStore 51 Session() SessionStore 52 OAuth() OAuthStore 53 System() SystemStore 54 Webhook() WebhookStore 55 Command() CommandStore 56 CommandWebhook() CommandWebhookStore 57 Preference() PreferenceStore 58 License() LicenseStore 59 Token() TokenStore 60 Emoji() EmojiStore 61 Status() StatusStore 62 FileInfo() FileInfoStore 63 Reaction() ReactionStore 64 Job() JobStore 65 UserAccessToken() UserAccessTokenStore 66 ChannelMemberHistory() ChannelMemberHistoryStore 67 Plugin() PluginStore 68 MarkSystemRanUnitTests() 69 Close() 70 DropAllTables() 71 TotalMasterDbConnections() int 72 TotalReadDbConnections() int 73 TotalSearchDbConnections() int 74 } 75 76 type TeamStore interface { 77 Save(team *model.Team) StoreChannel 78 Update(team *model.Team) StoreChannel 79 UpdateDisplayName(name string, teamId string) StoreChannel 80 Get(id string) StoreChannel 81 GetByName(name string) StoreChannel 82 SearchByName(name string) StoreChannel 83 SearchAll(term string) StoreChannel 84 SearchOpen(term string) StoreChannel 85 GetAll() StoreChannel 86 GetAllPage(offset int, limit int) StoreChannel 87 GetAllTeamListing() StoreChannel 88 GetAllTeamPageListing(offset int, limit int) StoreChannel 89 GetTeamsByUserId(userId string) StoreChannel 90 GetByInviteId(inviteId string) StoreChannel 91 PermanentDelete(teamId string) StoreChannel 92 AnalyticsTeamCount() StoreChannel 93 SaveMember(member *model.TeamMember, maxUsersPerTeam int) StoreChannel 94 UpdateMember(member *model.TeamMember) StoreChannel 95 GetMember(teamId string, userId string) StoreChannel 96 GetMembers(teamId string, offset int, limit int) StoreChannel 97 GetMembersByIds(teamId string, userIds []string) StoreChannel 98 GetTotalMemberCount(teamId string) StoreChannel 99 GetActiveMemberCount(teamId string) StoreChannel 100 GetTeamsForUser(userId string) StoreChannel 101 GetChannelUnreadsForAllTeams(excludeTeamId, userId string) StoreChannel 102 GetChannelUnreadsForTeam(teamId, userId string) StoreChannel 103 RemoveMember(teamId string, userId string) StoreChannel 104 RemoveAllMembersByTeam(teamId string) StoreChannel 105 RemoveAllMembersByUser(userId string) 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 ExtraUpdateByUser(userId string, time int64) StoreChannel 156 GetMembersForUser(teamId string, userId string) StoreChannel 157 AutocompleteInTeam(teamId string, term string) StoreChannel 158 SearchInTeam(teamId string, term string) StoreChannel 159 SearchMore(userId string, teamId string, term string) StoreChannel 160 GetMembersByIds(channelId string, userIds []string) StoreChannel 161 AnalyticsDeletedTypeCount(teamId string, channelType string) StoreChannel 162 GetChannelUnread(channelId, userId string) StoreChannel 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 InvalidateLastPostTimeCache(channelId string) 193 GetPostsCreatedAt(channelId string, time int64) StoreChannel 194 Overwrite(post *model.Post) StoreChannel 195 GetPostsByIds(postIds []string) StoreChannel 196 GetPostsBatchForIndexing(startTime int64, endTime int64, limit int) StoreChannel 197 PermanentDeleteBatch(endTime int64, limit int64) StoreChannel 198 GetOldest() StoreChannel 199 } 200 201 type UserStore interface { 202 Save(user *model.User) StoreChannel 203 Update(user *model.User, allowRoleUpdate bool) StoreChannel 204 UpdateLastPictureUpdate(userId string) StoreChannel 205 UpdateUpdateAt(userId string) StoreChannel 206 UpdatePassword(userId, newPassword string) StoreChannel 207 UpdateAuthData(userId string, service string, authData *string, email string, resetMfa bool) StoreChannel 208 UpdateMfaSecret(userId, secret string) StoreChannel 209 UpdateMfaActive(userId string, active bool) StoreChannel 210 Get(id string) StoreChannel 211 GetAll() StoreChannel 212 InvalidateProfilesInChannelCacheByUser(userId string) 213 InvalidateProfilesInChannelCache(channelId string) 214 GetProfilesInChannel(channelId string, offset int, limit int) StoreChannel 215 GetAllProfilesInChannel(channelId string, allowFromCache bool) StoreChannel 216 GetProfilesNotInChannel(teamId string, channelId string, offset int, limit int) StoreChannel 217 GetProfilesWithoutTeam(offset int, limit int) StoreChannel 218 GetProfilesByUsernames(usernames []string, teamId string) StoreChannel 219 GetAllProfiles(offset int, limit int) StoreChannel 220 GetProfiles(teamId string, offset int, limit int) StoreChannel 221 GetProfileByIds(userId []string, allowFromCache bool) StoreChannel 222 InvalidatProfileCacheForUser(userId string) 223 GetByEmail(email string) StoreChannel 224 GetByAuth(authData *string, authService string) StoreChannel 225 GetAllUsingAuthService(authService string) StoreChannel 226 GetByUsername(username string) StoreChannel 227 GetForLogin(loginId string, allowSignInWithUsername, allowSignInWithEmail, ldapEnabled bool) StoreChannel 228 VerifyEmail(userId string) StoreChannel 229 GetEtagForAllProfiles() StoreChannel 230 GetEtagForProfiles(teamId string) StoreChannel 231 UpdateFailedPasswordAttempts(userId string, attempts int) StoreChannel 232 GetTotalUsersCount() StoreChannel 233 GetSystemAdminProfiles() StoreChannel 234 PermanentDelete(userId string) StoreChannel 235 AnalyticsUniqueUserCount(teamId string) StoreChannel 236 AnalyticsActiveCount(time int64) StoreChannel 237 GetUnreadCount(userId string) StoreChannel 238 GetUnreadCountForChannel(userId string, channelId string) StoreChannel 239 GetRecentlyActiveUsersForTeam(teamId string, offset, limit int) StoreChannel 240 GetNewUsersForTeam(teamId string, offset, limit int) StoreChannel 241 Search(teamId string, term string, options map[string]bool) StoreChannel 242 SearchNotInTeam(notInTeamId string, term string, options map[string]bool) StoreChannel 243 SearchInChannel(channelId string, term string, options map[string]bool) StoreChannel 244 SearchNotInChannel(teamId string, channelId string, term string, options map[string]bool) StoreChannel 245 SearchWithoutTeam(term string, options map[string]bool) StoreChannel 246 AnalyticsGetInactiveUsersCount() StoreChannel 247 AnalyticsGetSystemAdminCount() StoreChannel 248 GetProfilesNotInTeam(teamId string, offset int, limit int) StoreChannel 249 GetEtagForProfilesNotInTeam(teamId string) StoreChannel 250 } 251 252 type SessionStore interface { 253 Save(session *model.Session) StoreChannel 254 Get(sessionIdOrToken string) StoreChannel 255 GetSessions(userId string) StoreChannel 256 GetSessionsWithActiveDeviceIds(userId string) StoreChannel 257 Remove(sessionIdOrToken string) StoreChannel 258 RemoveAllSessions() StoreChannel 259 PermanentDeleteSessionsByUser(teamId string) StoreChannel 260 UpdateLastActivityAt(sessionId string, time int64) StoreChannel 261 UpdateRoles(userId string, roles string) StoreChannel 262 UpdateDeviceId(id string, deviceId string, expiresAt int64) StoreChannel 263 AnalyticsSessionCount() StoreChannel 264 Cleanup(expiryTime int64, batchSize int64) 265 } 266 267 type AuditStore interface { 268 Save(audit *model.Audit) StoreChannel 269 Get(user_id string, offset int, limit int) StoreChannel 270 PermanentDeleteByUser(userId string) StoreChannel 271 PermanentDeleteBatch(endTime int64, limit int64) StoreChannel 272 } 273 274 type ClusterDiscoveryStore interface { 275 Save(discovery *model.ClusterDiscovery) StoreChannel 276 Delete(discovery *model.ClusterDiscovery) StoreChannel 277 Exists(discovery *model.ClusterDiscovery) StoreChannel 278 GetAll(discoveryType, clusterName string) StoreChannel 279 SetLastPingAt(discovery *model.ClusterDiscovery) StoreChannel 280 Cleanup() StoreChannel 281 } 282 283 type ComplianceStore interface { 284 Save(compliance *model.Compliance) StoreChannel 285 Update(compliance *model.Compliance) StoreChannel 286 Get(id string) StoreChannel 287 GetAll(offset, limit int) StoreChannel 288 ComplianceExport(compliance *model.Compliance) StoreChannel 289 MessageExport(after int64, limit int) StoreChannel 290 } 291 292 type OAuthStore interface { 293 SaveApp(app *model.OAuthApp) StoreChannel 294 UpdateApp(app *model.OAuthApp) StoreChannel 295 GetApp(id string) StoreChannel 296 GetAppByUser(userId string, offset, limit int) StoreChannel 297 GetApps(offset, limit int) StoreChannel 298 GetAuthorizedApps(userId string, offset, limit int) StoreChannel 299 DeleteApp(id string) StoreChannel 300 SaveAuthData(authData *model.AuthData) StoreChannel 301 GetAuthData(code string) StoreChannel 302 RemoveAuthData(code string) StoreChannel 303 PermanentDeleteAuthDataByUser(userId string) StoreChannel 304 SaveAccessData(accessData *model.AccessData) StoreChannel 305 UpdateAccessData(accessData *model.AccessData) StoreChannel 306 GetAccessData(token string) StoreChannel 307 GetAccessDataByUserForApp(userId, clientId string) StoreChannel 308 GetAccessDataByRefreshToken(token string) StoreChannel 309 GetPreviousAccessData(userId, clientId string) StoreChannel 310 RemoveAccessData(token string) StoreChannel 311 } 312 313 type SystemStore interface { 314 Save(system *model.System) StoreChannel 315 SaveOrUpdate(system *model.System) StoreChannel 316 Update(system *model.System) StoreChannel 317 Get() StoreChannel 318 GetByName(name string) StoreChannel 319 } 320 321 type WebhookStore interface { 322 SaveIncoming(webhook *model.IncomingWebhook) StoreChannel 323 GetIncoming(id string, allowFromCache bool) StoreChannel 324 GetIncomingList(offset, limit int) StoreChannel 325 GetIncomingByTeam(teamId string, offset, limit int) StoreChannel 326 UpdateIncoming(webhook *model.IncomingWebhook) StoreChannel 327 GetIncomingByChannel(channelId string) StoreChannel 328 DeleteIncoming(webhookId string, time int64) StoreChannel 329 PermanentDeleteIncomingByChannel(channelId string) StoreChannel 330 PermanentDeleteIncomingByUser(userId string) StoreChannel 331 332 SaveOutgoing(webhook *model.OutgoingWebhook) StoreChannel 333 GetOutgoing(id string) StoreChannel 334 GetOutgoingList(offset, limit int) StoreChannel 335 GetOutgoingByChannel(channelId string, offset, limit int) StoreChannel 336 GetOutgoingByTeam(teamId string, offset, limit int) StoreChannel 337 DeleteOutgoing(webhookId string, time int64) StoreChannel 338 PermanentDeleteOutgoingByChannel(channelId string) StoreChannel 339 PermanentDeleteOutgoingByUser(userId string) StoreChannel 340 UpdateOutgoing(hook *model.OutgoingWebhook) StoreChannel 341 342 AnalyticsIncomingCount(teamId string) StoreChannel 343 AnalyticsOutgoingCount(teamId string) StoreChannel 344 InvalidateWebhookCache(webhook string) 345 } 346 347 type CommandStore interface { 348 Save(webhook *model.Command) StoreChannel 349 Get(id string) StoreChannel 350 GetByTeam(teamId string) StoreChannel 351 GetByTrigger(teamId string, trigger string) StoreChannel 352 Delete(commandId string, time int64) StoreChannel 353 PermanentDeleteByTeam(teamId string) StoreChannel 354 PermanentDeleteByUser(userId string) StoreChannel 355 Update(hook *model.Command) StoreChannel 356 AnalyticsCommandCount(teamId string) StoreChannel 357 } 358 359 type CommandWebhookStore interface { 360 Save(webhook *model.CommandWebhook) StoreChannel 361 Get(id string) StoreChannel 362 TryUse(id string, limit int) StoreChannel 363 Cleanup() 364 } 365 366 type PreferenceStore interface { 367 Save(preferences *model.Preferences) StoreChannel 368 Get(userId string, category string, name string) StoreChannel 369 GetCategory(userId string, category string) StoreChannel 370 GetAll(userId string) StoreChannel 371 Delete(userId, category, name string) StoreChannel 372 DeleteCategory(userId string, category string) StoreChannel 373 DeleteCategoryAndName(category string, name string) StoreChannel 374 PermanentDeleteByUser(userId string) StoreChannel 375 IsFeatureEnabled(feature, userId string) StoreChannel 376 CleanupFlagsBatch(limit int64) StoreChannel 377 } 378 379 type LicenseStore interface { 380 Save(license *model.LicenseRecord) StoreChannel 381 Get(id string) StoreChannel 382 } 383 384 type TokenStore interface { 385 Save(recovery *model.Token) StoreChannel 386 Delete(token string) StoreChannel 387 GetByToken(token string) StoreChannel 388 Cleanup() 389 } 390 391 type EmojiStore interface { 392 Save(emoji *model.Emoji) StoreChannel 393 Get(id string, allowFromCache bool) StoreChannel 394 GetByName(name string) StoreChannel 395 GetList(offset, limit int, sort string) StoreChannel 396 Delete(id string, time int64) StoreChannel 397 Search(name string, prefixOnly bool, limit int) StoreChannel 398 } 399 400 type StatusStore interface { 401 SaveOrUpdate(status *model.Status) StoreChannel 402 Get(userId string) StoreChannel 403 GetByIds(userIds []string) StoreChannel 404 GetOnlineAway() StoreChannel 405 GetOnline() StoreChannel 406 GetAllFromTeam(teamId string) StoreChannel 407 ResetAll() StoreChannel 408 GetTotalActiveUsersCount() StoreChannel 409 UpdateLastActivityAt(userId string, lastActivityAt int64) StoreChannel 410 } 411 412 type FileInfoStore interface { 413 Save(info *model.FileInfo) StoreChannel 414 Get(id string) StoreChannel 415 GetByPath(path string) StoreChannel 416 GetForPost(postId string, readFromMaster bool, allowFromCache bool) StoreChannel 417 InvalidateFileInfosForPostCache(postId string) 418 AttachToPost(fileId string, postId string) StoreChannel 419 DeleteForPost(postId string) StoreChannel 420 PermanentDelete(fileId string) StoreChannel 421 PermanentDeleteBatch(endTime int64, limit int64) StoreChannel 422 } 423 424 type ReactionStore interface { 425 Save(reaction *model.Reaction) StoreChannel 426 Delete(reaction *model.Reaction) StoreChannel 427 GetForPost(postId string, allowFromCache bool) StoreChannel 428 DeleteAllWithEmojiName(emojiName string) StoreChannel 429 PermanentDeleteBatch(endTime int64, limit int64) StoreChannel 430 } 431 432 type JobStore interface { 433 Save(job *model.Job) StoreChannel 434 UpdateOptimistically(job *model.Job, currentStatus string) StoreChannel 435 UpdateStatus(id string, status string) StoreChannel 436 UpdateStatusOptimistically(id string, currentStatus string, newStatus string) StoreChannel 437 Get(id string) StoreChannel 438 GetAllPage(offset int, limit int) StoreChannel 439 GetAllByType(jobType string) StoreChannel 440 GetAllByTypePage(jobType string, offset int, limit int) StoreChannel 441 GetAllByStatus(status string) StoreChannel 442 GetNewestJobByStatusAndType(status string, jobType string) StoreChannel 443 GetCountByStatusAndType(status string, jobType string) StoreChannel 444 Delete(id string) StoreChannel 445 } 446 447 type UserAccessTokenStore interface { 448 Save(token *model.UserAccessToken) StoreChannel 449 Delete(tokenId string) StoreChannel 450 DeleteAllForUser(userId string) StoreChannel 451 Get(tokenId string) StoreChannel 452 GetAll(offset int, limit int) StoreChannel 453 GetByToken(tokenString string) StoreChannel 454 GetByUser(userId string, page, perPage int) StoreChannel 455 Search(term string) StoreChannel 456 UpdateTokenEnable(tokenId string) StoreChannel 457 UpdateTokenDisable(tokenId string) StoreChannel 458 } 459 460 type PluginStore interface { 461 SaveOrUpdate(keyVal *model.PluginKeyValue) StoreChannel 462 Get(pluginId, key string) StoreChannel 463 Delete(pluginId, key string) StoreChannel 464 }