fileinfostore (#15236)
* Migration completed * Fix i18n * Fix imports * Fix typos and improvements * Add new error handling case * Fix i18n * Fix store layers * Fix shadowing vars * Lint: remove unnecessary use of sprintf * Lint: remove unnecessary use of sprint * Adding the translation message * trigger CI Co-authored-by: Rodrigo Villablanca <villa061004@gmail.com> Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
7cc26bf659
Коммит
b451b3cf86
76
app/file.go
76
app/file.go
@@ -7,6 +7,7 @@ import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
@@ -33,6 +34,7 @@ import (
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/plugin"
|
||||
"github.com/mattermost/mattermost-server/v5/services/filesstore"
|
||||
"github.com/mattermost/mattermost-server/v5/store"
|
||||
"github.com/mattermost/mattermost-server/v5/utils"
|
||||
)
|
||||
|
||||
@@ -297,13 +299,12 @@ func (a *App) MigrateFilenamesToFileInfos(post *model.Post) []*model.FileInfo {
|
||||
return []*model.FileInfo{}
|
||||
}
|
||||
|
||||
var err *model.AppError
|
||||
if newPost := result.Posts[post.Id]; len(newPost.Filenames) != len(post.Filenames) {
|
||||
// Another thread has already created FileInfos for this post, so just return those
|
||||
var fileInfos []*model.FileInfo
|
||||
fileInfos, err = a.Srv().Store.FileInfo().GetForPost(post.Id, true, false, false)
|
||||
if err != nil {
|
||||
mlog.Error("Unable to get FileInfos for migrated post", mlog.Err(err), mlog.String("post_id", post.Id))
|
||||
fileInfos, nErr = a.Srv().Store.FileInfo().GetForPost(post.Id, true, false, false)
|
||||
if nErr != nil {
|
||||
mlog.Error("Unable to get FileInfos for migrated post", mlog.Err(nErr), mlog.String("post_id", post.Id))
|
||||
return []*model.FileInfo{}
|
||||
}
|
||||
|
||||
@@ -316,13 +317,13 @@ func (a *App) MigrateFilenamesToFileInfos(post *model.Post) []*model.FileInfo {
|
||||
savedInfos := make([]*model.FileInfo, 0, len(infos))
|
||||
fileIds := make([]string, 0, len(filenames))
|
||||
for _, info := range infos {
|
||||
if _, err = a.Srv().Store.FileInfo().Save(info); err != nil {
|
||||
if _, nErr = a.Srv().Store.FileInfo().Save(info); nErr != nil {
|
||||
mlog.Error(
|
||||
"Unable to save file info when migrating post to use FileInfos",
|
||||
mlog.String("post_id", post.Id),
|
||||
mlog.String("file_info_id", info.Id),
|
||||
mlog.String("file_info_path", info.Path),
|
||||
mlog.Err(err),
|
||||
mlog.Err(nErr),
|
||||
)
|
||||
continue
|
||||
}
|
||||
@@ -542,7 +543,7 @@ type UploadFileTask struct {
|
||||
// Testing: overrideable dependency functions
|
||||
pluginsEnvironment *plugin.Environment
|
||||
writeFile func(io.Reader, string) (int64, *model.AppError)
|
||||
saveToDatabase func(*model.FileInfo) (*model.FileInfo, *model.AppError)
|
||||
saveToDatabase func(*model.FileInfo) (*model.FileInfo, error)
|
||||
}
|
||||
|
||||
func (t *UploadFileTask) init(a *App) {
|
||||
@@ -640,7 +641,13 @@ func (a *App) UploadFileX(channelId, name string, input io.Reader,
|
||||
}
|
||||
|
||||
if _, err := t.saveToDatabase(t.fileinfo); err != nil {
|
||||
return nil, err
|
||||
var appErr *model.AppError
|
||||
switch {
|
||||
case errors.As(err, &appErr):
|
||||
return nil, appErr
|
||||
default:
|
||||
return nil, model.NewAppError("UploadFileX", "app.file_info.save.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
@@ -961,7 +968,13 @@ func (a *App) DoUploadFileExpectModification(now time.Time, rawTeamId string, ra
|
||||
}
|
||||
|
||||
if _, err := a.Srv().Store.FileInfo().Save(info); err != nil {
|
||||
return nil, data, err
|
||||
var appErr *model.AppError
|
||||
switch {
|
||||
case errors.As(err, &appErr):
|
||||
return nil, data, appErr
|
||||
default:
|
||||
return nil, data, model.NewAppError("DoUploadFileExpectModification", "app.file_info.save.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
return info, data, nil
|
||||
@@ -1104,11 +1117,36 @@ func (a *App) generatePreviewImage(img image.Image, previewPath string, width in
|
||||
}
|
||||
|
||||
func (a *App) GetFileInfo(fileId string) (*model.FileInfo, *model.AppError) {
|
||||
return a.Srv().Store.FileInfo().Get(fileId)
|
||||
fileInfo, err := a.Srv().Store.FileInfo().Get(fileId)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(err, &nfErr):
|
||||
return nil, model.NewAppError("GetFileInfo", "app.file_info.get.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
default:
|
||||
return nil, model.NewAppError("GetFileInfo", "app.file_info.get.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
return fileInfo, nil
|
||||
}
|
||||
|
||||
func (a *App) GetFileInfos(page, perPage int, opt *model.GetFileInfosOptions) ([]*model.FileInfo, *model.AppError) {
|
||||
return a.Srv().Store.FileInfo().GetWithOptions(page, perPage, opt)
|
||||
fileInfos, err := a.Srv().Store.FileInfo().GetWithOptions(page, perPage, opt)
|
||||
if err != nil {
|
||||
var invErr *store.ErrInvalidInput
|
||||
var ltErr *store.ErrLimitExceeded
|
||||
switch {
|
||||
case errors.As(err, &invErr):
|
||||
return nil, model.NewAppError("GetFileInfos", "app.file_info.get_with_options.app_error", nil, invErr.Error(), http.StatusBadRequest)
|
||||
case errors.As(err, <Err):
|
||||
return nil, model.NewAppError("GetFileInfos", "app.file_info.get_with_options.app_error", nil, ltErr.Error(), http.StatusBadRequest)
|
||||
default:
|
||||
return nil, model.NewAppError("GetFileInfos", "app.file_info.get_with_options.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
return fileInfos, nil
|
||||
}
|
||||
|
||||
func (a *App) GetFile(fileId string) ([]byte, *model.AppError) {
|
||||
@@ -1133,7 +1171,13 @@ func (a *App) CopyFileInfos(userId string, fileIds []string) ([]string, *model.A
|
||||
for _, fileId := range fileIds {
|
||||
fileInfo, err := a.Srv().Store.FileInfo().Get(fileId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(err, &nfErr):
|
||||
return nil, model.NewAppError("CopyFileInfos", "app.file_info.get.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
default:
|
||||
return nil, model.NewAppError("CopyFileInfos", "app.file_info.get.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
fileInfo.Id = model.NewId()
|
||||
@@ -1143,7 +1187,13 @@ func (a *App) CopyFileInfos(userId string, fileIds []string) ([]string, *model.A
|
||||
fileInfo.PostId = ""
|
||||
|
||||
if _, err := a.Srv().Store.FileInfo().Save(fileInfo); err != nil {
|
||||
return newFileIds, err
|
||||
var appErr *model.AppError
|
||||
switch {
|
||||
case errors.As(err, &appErr):
|
||||
return nil, appErr
|
||||
default:
|
||||
return nil, model.NewAppError("CopyFileInfos", "app.file_info.save.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
newFileIds = append(newFileIds, fileInfo.Id)
|
||||
|
||||
@@ -51,7 +51,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
fchan = make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
fileInfos, err := a.Srv().Store.FileInfo().GetForPost(post.Id, true, false, true)
|
||||
fchan <- store.StoreResult{Data: fileInfos, Err: err}
|
||||
fchan <- store.StoreResult{Data: fileInfos, NErr: err}
|
||||
close(fchan)
|
||||
}()
|
||||
}
|
||||
@@ -349,8 +349,8 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
message.Add("otherFile", "true")
|
||||
|
||||
var infos []*model.FileInfo
|
||||
if result := <-fchan; result.Err != nil {
|
||||
mlog.Warn("Unable to get fileInfo for push notifications.", mlog.String("post_id", post.Id), mlog.Err(result.Err))
|
||||
if result := <-fchan; result.NErr != nil {
|
||||
mlog.Warn("Unable to get fileInfo for push notifications.", mlog.String("post_id", post.Id), mlog.Err(result.NErr))
|
||||
} else {
|
||||
infos = result.Data.([]*model.FileInfo)
|
||||
}
|
||||
|
||||
@@ -1146,7 +1146,12 @@ func (a *App) GetFileInfosForPostWithMigration(postId string) ([]*model.FileInfo
|
||||
}
|
||||
|
||||
func (a *App) GetFileInfosForPost(postId string, fromMaster bool) ([]*model.FileInfo, *model.AppError) {
|
||||
return a.Srv().Store.FileInfo().GetForPost(postId, fromMaster, false, true)
|
||||
fileInfos, err := a.Srv().Store.FileInfo().GetForPost(postId, fromMaster, false, true)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetFileInfosForPost", "app.file_info.get_for_post.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return fileInfos, nil
|
||||
}
|
||||
|
||||
func (a *App) PostWithProxyAddedToImageURLs(post *model.Post) *model.Post {
|
||||
|
||||
@@ -1535,7 +1535,7 @@ func (a *App) PermanentDeleteUser(user *model.User) *model.AppError {
|
||||
}
|
||||
|
||||
if _, err := a.Srv().Store.FileInfo().PermanentDeleteByUser(user.Id); err != nil {
|
||||
return err
|
||||
return model.NewAppError("PermanentDeleteUser", "app.file_info.permanent_delete_by_user.app_error", nil, ""+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if err := a.Srv().Store.User().PermanentDelete(user.Id); err != nil {
|
||||
|
||||
80
i18n/en.json
80
i18n/en.json
@@ -3438,6 +3438,26 @@
|
||||
"id": "app.export.export_write_line.json_marshall.error",
|
||||
"translation": "An error occurred marshalling the JSON data for export."
|
||||
},
|
||||
{
|
||||
"id": "app.file_info.get.app_error",
|
||||
"translation": "Unable to get the file info."
|
||||
},
|
||||
{
|
||||
"id": "app.file_info.get_for_post.app_error",
|
||||
"translation": "Unable to get the file info for the post."
|
||||
},
|
||||
{
|
||||
"id": "app.file_info.get_with_options.app_error",
|
||||
"translation": "Unable to get the file info with options"
|
||||
},
|
||||
{
|
||||
"id": "app.file_info.permanent_delete_by_user.app_error",
|
||||
"translation": "Unable to delete attachments of the user."
|
||||
},
|
||||
{
|
||||
"id": "app.file_info.save.app_error",
|
||||
"translation": "Unable to save the file info."
|
||||
},
|
||||
{
|
||||
"id": "app.import.attachment.bad_file.error",
|
||||
"translation": "Error reading the file at: \"{{.FilePath}}\""
|
||||
@@ -5006,6 +5026,10 @@
|
||||
"id": "ent.data_retention.channel_member_history_batch.internal_error",
|
||||
"translation": "Failed to purge records."
|
||||
},
|
||||
{
|
||||
"id": "ent.data_retention.file_infos_batch.internal_error",
|
||||
"translation": "We encountered an error permanently deleting the batch of file infos."
|
||||
},
|
||||
{
|
||||
"id": "ent.data_retention.flags_batch.internal_error",
|
||||
"translation": "We encountered an error cleaning up the batch of flags."
|
||||
@@ -5330,6 +5354,14 @@
|
||||
"id": "ent.ldap_id_migrate.app_error",
|
||||
"translation": "unable to migrate."
|
||||
},
|
||||
{
|
||||
"id": "ent.message_export.actiance_export.get_attachment_error",
|
||||
"translation": "Failed to get file info for a post."
|
||||
},
|
||||
{
|
||||
"id": "ent.message_export.csv_export.get_attachment_error",
|
||||
"translation": "Failed to get file info for a post."
|
||||
},
|
||||
{
|
||||
"id": "ent.message_export.global_relay.attach_file.app_error",
|
||||
"translation": "Unable to add attachment to the Global Relay export."
|
||||
@@ -5382,6 +5414,10 @@
|
||||
"id": "ent.message_export.global_relay_export.deliver.unable_to_open_zip_file_data.app_error",
|
||||
"translation": "Unable to open the export temporary file."
|
||||
},
|
||||
{
|
||||
"id": "ent.message_export.global_relay_export.get_attachment_error",
|
||||
"translation": "Failed to get file info for a post."
|
||||
},
|
||||
{
|
||||
"id": "ent.message_export.run_export.app_error",
|
||||
"translation": "Failed to select message export data."
|
||||
@@ -7190,50 +7226,6 @@
|
||||
"id": "store.sql_command.update.missing.app_error",
|
||||
"translation": "Command does not exist."
|
||||
},
|
||||
{
|
||||
"id": "store.sql_file_info.PermanentDeleteByUser.app_error",
|
||||
"translation": "Unable to delete attachments of the user."
|
||||
},
|
||||
{
|
||||
"id": "store.sql_file_info.attach_to_post.app_error",
|
||||
"translation": "Unable to attach the file info to the post."
|
||||
},
|
||||
{
|
||||
"id": "store.sql_file_info.delete_for_post.app_error",
|
||||
"translation": "Unable to delete the file info to the post."
|
||||
},
|
||||
{
|
||||
"id": "store.sql_file_info.get.app_error",
|
||||
"translation": "Unable to get the file info."
|
||||
},
|
||||
{
|
||||
"id": "store.sql_file_info.get_by_path.app_error",
|
||||
"translation": "Unable to get the file info by path."
|
||||
},
|
||||
{
|
||||
"id": "store.sql_file_info.get_for_post.app_error",
|
||||
"translation": "Unable to get the file info for the post."
|
||||
},
|
||||
{
|
||||
"id": "store.sql_file_info.get_for_user_id.app_error",
|
||||
"translation": "Unable to get the file info for the user."
|
||||
},
|
||||
{
|
||||
"id": "store.sql_file_info.get_with_options.app_error",
|
||||
"translation": "Unable to get the file info with options"
|
||||
},
|
||||
{
|
||||
"id": "store.sql_file_info.permanent_delete.app_error",
|
||||
"translation": "Unable to permanently delete the file info."
|
||||
},
|
||||
{
|
||||
"id": "store.sql_file_info.permanent_delete_batch.app_error",
|
||||
"translation": "We encountered an error permanently deleting the batch of file infos."
|
||||
},
|
||||
{
|
||||
"id": "store.sql_file_info.save.app_error",
|
||||
"translation": "Unable to save the file info."
|
||||
},
|
||||
{
|
||||
"id": "store.sql_group.app_error",
|
||||
"translation": "failed to build query."
|
||||
|
||||
@@ -21,7 +21,7 @@ func (s *LocalCacheFileInfoStore) handleClusterInvalidateFileInfo(msg *model.Clu
|
||||
s.rootStore.fileInfoCache.Remove(msg.Data)
|
||||
}
|
||||
|
||||
func (s LocalCacheFileInfoStore) GetForPost(postId string, readFromMaster, includeDeleted, allowFromCache bool) ([]*model.FileInfo, *model.AppError) {
|
||||
func (s LocalCacheFileInfoStore) GetForPost(postId string, readFromMaster, includeDeleted, allowFromCache bool) ([]*model.FileInfo, error) {
|
||||
if !allowFromCache {
|
||||
return s.FileInfoStore.GetForPost(postId, readFromMaster, includeDeleted, allowFromCache)
|
||||
}
|
||||
|
||||
@@ -2867,7 +2867,7 @@ func (s *OpenTracingLayerEmojiStore) Search(name string, prefixOnly bool, limit
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerFileInfoStore) AttachToPost(fileId string, postId string, creatorId string) *model.AppError {
|
||||
func (s *OpenTracingLayerFileInfoStore) AttachToPost(fileId string, postId string, creatorId string) error {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "FileInfoStore.AttachToPost")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -2898,7 +2898,7 @@ func (s *OpenTracingLayerFileInfoStore) ClearCaches() {
|
||||
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerFileInfoStore) DeleteForPost(postId string) (string, *model.AppError) {
|
||||
func (s *OpenTracingLayerFileInfoStore) DeleteForPost(postId string) (string, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "FileInfoStore.DeleteForPost")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -2916,7 +2916,7 @@ func (s *OpenTracingLayerFileInfoStore) DeleteForPost(postId string) (string, *m
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerFileInfoStore) Get(id string) (*model.FileInfo, *model.AppError) {
|
||||
func (s *OpenTracingLayerFileInfoStore) Get(id string) (*model.FileInfo, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "FileInfoStore.Get")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -2934,7 +2934,7 @@ func (s *OpenTracingLayerFileInfoStore) Get(id string) (*model.FileInfo, *model.
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerFileInfoStore) GetByPath(path string) (*model.FileInfo, *model.AppError) {
|
||||
func (s *OpenTracingLayerFileInfoStore) GetByPath(path string) (*model.FileInfo, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "FileInfoStore.GetByPath")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -2952,7 +2952,7 @@ func (s *OpenTracingLayerFileInfoStore) GetByPath(path string) (*model.FileInfo,
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerFileInfoStore) GetForPost(postId string, readFromMaster bool, includeDeleted bool, allowFromCache bool) ([]*model.FileInfo, *model.AppError) {
|
||||
func (s *OpenTracingLayerFileInfoStore) GetForPost(postId string, readFromMaster bool, includeDeleted bool, allowFromCache bool) ([]*model.FileInfo, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "FileInfoStore.GetForPost")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -2970,7 +2970,7 @@ func (s *OpenTracingLayerFileInfoStore) GetForPost(postId string, readFromMaster
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerFileInfoStore) GetForUser(userId string) ([]*model.FileInfo, *model.AppError) {
|
||||
func (s *OpenTracingLayerFileInfoStore) GetForUser(userId string) ([]*model.FileInfo, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "FileInfoStore.GetForUser")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -2988,7 +2988,7 @@ func (s *OpenTracingLayerFileInfoStore) GetForUser(userId string) ([]*model.File
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerFileInfoStore) GetWithOptions(page int, perPage int, opt *model.GetFileInfosOptions) ([]*model.FileInfo, *model.AppError) {
|
||||
func (s *OpenTracingLayerFileInfoStore) GetWithOptions(page int, perPage int, opt *model.GetFileInfosOptions) ([]*model.FileInfo, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "FileInfoStore.GetWithOptions")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -3019,7 +3019,7 @@ func (s *OpenTracingLayerFileInfoStore) InvalidateFileInfosForPostCache(postId s
|
||||
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerFileInfoStore) PermanentDelete(fileId string) *model.AppError {
|
||||
func (s *OpenTracingLayerFileInfoStore) PermanentDelete(fileId string) error {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "FileInfoStore.PermanentDelete")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -3037,7 +3037,7 @@ func (s *OpenTracingLayerFileInfoStore) PermanentDelete(fileId string) *model.Ap
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerFileInfoStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, *model.AppError) {
|
||||
func (s *OpenTracingLayerFileInfoStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "FileInfoStore.PermanentDeleteBatch")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -3055,7 +3055,7 @@ func (s *OpenTracingLayerFileInfoStore) PermanentDeleteBatch(endTime int64, limi
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerFileInfoStore) PermanentDeleteByUser(userId string) (int64, *model.AppError) {
|
||||
func (s *OpenTracingLayerFileInfoStore) PermanentDeleteByUser(userId string) (int64, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "FileInfoStore.PermanentDeleteByUser")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -3073,7 +3073,7 @@ func (s *OpenTracingLayerFileInfoStore) PermanentDeleteByUser(userId string) (in
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerFileInfoStore) Save(info *model.FileInfo) (*model.FileInfo, *model.AppError) {
|
||||
func (s *OpenTracingLayerFileInfoStore) Save(info *model.FileInfo) (*model.FileInfo, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "FileInfoStore.Save")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
|
||||
@@ -2150,9 +2150,23 @@ func (s *RetryLayerEmojiStore) Search(name string, prefixOnly bool, limit int) (
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerFileInfoStore) AttachToPost(fileId string, postId string, creatorId string) *model.AppError {
|
||||
func (s *RetryLayerFileInfoStore) AttachToPost(fileId string, postId string, creatorId string) error {
|
||||
|
||||
return s.FileInfoStore.AttachToPost(fileId, postId, creatorId)
|
||||
tries := 0
|
||||
for {
|
||||
err := s.FileInfoStore.AttachToPost(fileId, postId, creatorId)
|
||||
if err == nil {
|
||||
return err
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2162,39 +2176,123 @@ func (s *RetryLayerFileInfoStore) ClearCaches() {
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerFileInfoStore) DeleteForPost(postId string) (string, *model.AppError) {
|
||||
func (s *RetryLayerFileInfoStore) DeleteForPost(postId string) (string, error) {
|
||||
|
||||
return s.FileInfoStore.DeleteForPost(postId)
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.FileInfoStore.DeleteForPost(postId)
|
||||
if err == nil {
|
||||
return result, err
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerFileInfoStore) Get(id string) (*model.FileInfo, *model.AppError) {
|
||||
func (s *RetryLayerFileInfoStore) Get(id string) (*model.FileInfo, error) {
|
||||
|
||||
return s.FileInfoStore.Get(id)
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.FileInfoStore.Get(id)
|
||||
if err == nil {
|
||||
return result, err
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerFileInfoStore) GetByPath(path string) (*model.FileInfo, *model.AppError) {
|
||||
func (s *RetryLayerFileInfoStore) GetByPath(path string) (*model.FileInfo, error) {
|
||||
|
||||
return s.FileInfoStore.GetByPath(path)
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.FileInfoStore.GetByPath(path)
|
||||
if err == nil {
|
||||
return result, err
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerFileInfoStore) GetForPost(postId string, readFromMaster bool, includeDeleted bool, allowFromCache bool) ([]*model.FileInfo, *model.AppError) {
|
||||
func (s *RetryLayerFileInfoStore) GetForPost(postId string, readFromMaster bool, includeDeleted bool, allowFromCache bool) ([]*model.FileInfo, error) {
|
||||
|
||||
return s.FileInfoStore.GetForPost(postId, readFromMaster, includeDeleted, allowFromCache)
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.FileInfoStore.GetForPost(postId, readFromMaster, includeDeleted, allowFromCache)
|
||||
if err == nil {
|
||||
return result, err
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerFileInfoStore) GetForUser(userId string) ([]*model.FileInfo, *model.AppError) {
|
||||
func (s *RetryLayerFileInfoStore) GetForUser(userId string) ([]*model.FileInfo, error) {
|
||||
|
||||
return s.FileInfoStore.GetForUser(userId)
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.FileInfoStore.GetForUser(userId)
|
||||
if err == nil {
|
||||
return result, err
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerFileInfoStore) GetWithOptions(page int, perPage int, opt *model.GetFileInfosOptions) ([]*model.FileInfo, *model.AppError) {
|
||||
func (s *RetryLayerFileInfoStore) GetWithOptions(page int, perPage int, opt *model.GetFileInfosOptions) ([]*model.FileInfo, error) {
|
||||
|
||||
return s.FileInfoStore.GetWithOptions(page, perPage, opt)
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.FileInfoStore.GetWithOptions(page, perPage, opt)
|
||||
if err == nil {
|
||||
return result, err
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2204,27 +2302,83 @@ func (s *RetryLayerFileInfoStore) InvalidateFileInfosForPostCache(postId string,
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerFileInfoStore) PermanentDelete(fileId string) *model.AppError {
|
||||
func (s *RetryLayerFileInfoStore) PermanentDelete(fileId string) error {
|
||||
|
||||
return s.FileInfoStore.PermanentDelete(fileId)
|
||||
tries := 0
|
||||
for {
|
||||
err := s.FileInfoStore.PermanentDelete(fileId)
|
||||
if err == nil {
|
||||
return err
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerFileInfoStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, *model.AppError) {
|
||||
func (s *RetryLayerFileInfoStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, error) {
|
||||
|
||||
return s.FileInfoStore.PermanentDeleteBatch(endTime, limit)
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.FileInfoStore.PermanentDeleteBatch(endTime, limit)
|
||||
if err == nil {
|
||||
return result, err
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerFileInfoStore) PermanentDeleteByUser(userId string) (int64, *model.AppError) {
|
||||
func (s *RetryLayerFileInfoStore) PermanentDeleteByUser(userId string) (int64, error) {
|
||||
|
||||
return s.FileInfoStore.PermanentDeleteByUser(userId)
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.FileInfoStore.PermanentDeleteByUser(userId)
|
||||
if err == nil {
|
||||
return result, err
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerFileInfoStore) Save(info *model.FileInfo) (*model.FileInfo, *model.AppError) {
|
||||
func (s *RetryLayerFileInfoStore) Save(info *model.FileInfo) (*model.FileInfo, error) {
|
||||
|
||||
return s.FileInfoStore.Save(info)
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.FileInfoStore.Save(info)
|
||||
if err == nil {
|
||||
return result, err
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@ package sqlstore
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
@@ -52,19 +52,19 @@ func (fs SqlFileInfoStore) createIndexesIfNotExists() {
|
||||
fs.CreateIndexIfNotExists("idx_fileinfo_postid_at", "FileInfo", "PostId")
|
||||
}
|
||||
|
||||
func (fs SqlFileInfoStore) Save(info *model.FileInfo) (*model.FileInfo, *model.AppError) {
|
||||
func (fs SqlFileInfoStore) Save(info *model.FileInfo) (*model.FileInfo, error) {
|
||||
info.PreSave()
|
||||
if err := info.IsValid(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := fs.GetMaster().Insert(info); err != nil {
|
||||
return nil, model.NewAppError("SqlFileInfoStore.Save", "store.sql_file_info.save.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, errors.Wrap(err, "failed to save FileInfo")
|
||||
}
|
||||
return info, nil
|
||||
}
|
||||
|
||||
func (fs SqlFileInfoStore) Get(id string) (*model.FileInfo, *model.AppError) {
|
||||
func (fs SqlFileInfoStore) Get(id string) (*model.FileInfo, error) {
|
||||
info := &model.FileInfo{}
|
||||
|
||||
if err := fs.GetReplica().SelectOne(info,
|
||||
@@ -76,17 +76,18 @@ func (fs SqlFileInfoStore) Get(id string) (*model.FileInfo, *model.AppError) {
|
||||
Id = :Id
|
||||
AND DeleteAt = 0`, map[string]interface{}{"Id": id}); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, model.NewAppError("SqlFileInfoStore.Get", "store.sql_file_info.get.app_error", nil, "id="+id+", "+err.Error(), http.StatusNotFound)
|
||||
return nil, store.NewErrNotFound("FileInfo", id)
|
||||
}
|
||||
return nil, model.NewAppError("SqlFileInfoStore.Get", "store.sql_file_info.get.app_error", nil, "id="+id+", "+err.Error(), http.StatusInternalServerError)
|
||||
return nil, errors.Wrapf(err, "failed to get FileInfo with id=%s", id)
|
||||
}
|
||||
return info, nil
|
||||
}
|
||||
|
||||
func (fs SqlFileInfoStore) GetWithOptions(page, perPage int, opt *model.GetFileInfosOptions) ([]*model.FileInfo, *model.AppError) {
|
||||
if perPage < 0 || page < 0 {
|
||||
return nil, model.NewAppError("SqlFileInfoStore.GetWithOptions",
|
||||
"store.sql_file_info.get_with_options.app_error", nil, fmt.Sprintf("page=%d and perPage=%d must be non-negative", page, perPage), http.StatusBadRequest)
|
||||
func (fs SqlFileInfoStore) GetWithOptions(page, perPage int, opt *model.GetFileInfosOptions) ([]*model.FileInfo, error) {
|
||||
if perPage < 0 {
|
||||
return nil, store.NewErrLimitExceeded("perPage", perPage, "value used in pagination while getting FileInfos")
|
||||
} else if page < 0 {
|
||||
return nil, store.NewErrLimitExceeded("page", page, "value used in pagination while getting FileInfos")
|
||||
}
|
||||
if perPage == 0 {
|
||||
return nil, nil
|
||||
@@ -131,8 +132,7 @@ func (fs SqlFileInfoStore) GetWithOptions(page, perPage int, opt *model.GetFileI
|
||||
case model.FILEINFO_SORT_BY_SIZE:
|
||||
query = query.OrderBy("FileInfo.Size " + sortDirection)
|
||||
default:
|
||||
return nil, model.NewAppError("SqlFileInfoStore.GetWithOptions",
|
||||
"store.sql_file_info.get_with_options.app_error", nil, "invalid sort option", http.StatusBadRequest)
|
||||
return nil, store.NewErrInvalidInput("FileInfo", "<sortOption>", opt.SortBy)
|
||||
}
|
||||
|
||||
query = query.OrderBy("FileInfo.Id ASC") // secondary sort for sort stability
|
||||
@@ -141,18 +141,16 @@ func (fs SqlFileInfoStore) GetWithOptions(page, perPage int, opt *model.GetFileI
|
||||
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlFileInfoStore.GetWithOptions",
|
||||
"store.sql.build_query.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, errors.Wrap(err, "file_info_tosql")
|
||||
}
|
||||
var infos []*model.FileInfo
|
||||
if _, err := fs.GetReplica().Select(&infos, queryString, args...); err != nil {
|
||||
return nil, model.NewAppError("SqlFileInfoStore.GetWithOptions",
|
||||
"store.sql_file_info.get_with_options.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, errors.Wrap(err, "failed to find FileInfos")
|
||||
}
|
||||
return infos, nil
|
||||
}
|
||||
|
||||
func (fs SqlFileInfoStore) GetByPath(path string) (*model.FileInfo, *model.AppError) {
|
||||
func (fs SqlFileInfoStore) GetByPath(path string) (*model.FileInfo, error) {
|
||||
info := &model.FileInfo{}
|
||||
|
||||
if err := fs.GetReplica().SelectOne(info,
|
||||
@@ -164,7 +162,11 @@ func (fs SqlFileInfoStore) GetByPath(path string) (*model.FileInfo, *model.AppEr
|
||||
Path = :Path
|
||||
AND DeleteAt = 0
|
||||
LIMIT 1`, map[string]interface{}{"Path": path}); err != nil {
|
||||
return nil, model.NewAppError("SqlFileInfoStore.GetByPath", "store.sql_file_info.get_by_path.app_error", nil, "path="+path+", "+err.Error(), http.StatusInternalServerError)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("FileInfo", fmt.Sprintf("path=%s", path))
|
||||
}
|
||||
|
||||
return nil, errors.Wrapf(err, "failed to get FileInfo with path=%s", path)
|
||||
}
|
||||
return info, nil
|
||||
}
|
||||
@@ -172,7 +174,7 @@ func (fs SqlFileInfoStore) GetByPath(path string) (*model.FileInfo, *model.AppEr
|
||||
func (fs SqlFileInfoStore) InvalidateFileInfosForPostCache(postId string, deleted bool) {
|
||||
}
|
||||
|
||||
func (fs SqlFileInfoStore) GetForPost(postId string, readFromMaster, includeDeleted, allowFromCache bool) ([]*model.FileInfo, *model.AppError) {
|
||||
func (fs SqlFileInfoStore) GetForPost(postId string, readFromMaster, includeDeleted, allowFromCache bool) ([]*model.FileInfo, error) {
|
||||
var infos []*model.FileInfo
|
||||
|
||||
dbmap := fs.GetReplica()
|
||||
@@ -193,17 +195,16 @@ func (fs SqlFileInfoStore) GetForPost(postId string, readFromMaster, includeDele
|
||||
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlFileInfoStore.GetForPost", "store.sql_file_info.get_for_post.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, errors.Wrap(err, "file_info_tosql")
|
||||
}
|
||||
|
||||
if _, err := dbmap.Select(&infos, queryString, args...); err != nil {
|
||||
return nil, model.NewAppError("SqlFileInfoStore.GetForPost",
|
||||
"store.sql_file_info.get_for_post.app_error", nil, "post_id="+postId+", "+err.Error(), http.StatusInternalServerError)
|
||||
return nil, errors.Wrapf(err, "failed to find FileInfos with postId=%s", postId)
|
||||
}
|
||||
return infos, nil
|
||||
}
|
||||
|
||||
func (fs SqlFileInfoStore) GetForUser(userId string) ([]*model.FileInfo, *model.AppError) {
|
||||
func (fs SqlFileInfoStore) GetForUser(userId string) ([]*model.FileInfo, error) {
|
||||
var infos []*model.FileInfo
|
||||
|
||||
dbmap := fs.GetReplica()
|
||||
@@ -218,13 +219,12 @@ func (fs SqlFileInfoStore) GetForUser(userId string) ([]*model.FileInfo, *model.
|
||||
AND DeleteAt = 0
|
||||
ORDER BY
|
||||
CreateAt`, map[string]interface{}{"CreatorId": userId}); err != nil {
|
||||
return nil, model.NewAppError("SqlFileInfoStore.GetForUser",
|
||||
"store.sql_file_info.get_for_user_id.app_error", nil, "creator_id="+userId+", "+err.Error(), http.StatusInternalServerError)
|
||||
return nil, errors.Wrapf(err, "failed to find FileInfos with creatorId=%s", userId)
|
||||
}
|
||||
return infos, nil
|
||||
}
|
||||
|
||||
func (fs SqlFileInfoStore) AttachToPost(fileId, postId, creatorId string) *model.AppError {
|
||||
func (fs SqlFileInfoStore) AttachToPost(fileId, postId, creatorId string) error {
|
||||
sqlResult, err := fs.GetMaster().Exec(`
|
||||
UPDATE
|
||||
FileInfo
|
||||
@@ -240,24 +240,21 @@ func (fs SqlFileInfoStore) AttachToPost(fileId, postId, creatorId string) *model
|
||||
"CreatorId": creatorId,
|
||||
})
|
||||
if err != nil {
|
||||
return model.NewAppError("SqlFileInfoStore.AttachToPost",
|
||||
"store.sql_file_info.attach_to_post.app_error", nil, "post_id="+postId+", file_id="+fileId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
return errors.Wrapf(err, "failed to update FileInfo with id=%s and postId=%s", fileId, postId)
|
||||
}
|
||||
|
||||
count, err := sqlResult.RowsAffected()
|
||||
if err != nil {
|
||||
// RowsAffected should never fail with the MySQL or Postgres drivers
|
||||
return model.NewAppError("SqlFileInfoStore.AttachToPost",
|
||||
"store.sql_file_info.attach_to_post.app_error", nil, "post_id="+postId+", file_id="+fileId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
return errors.Wrap(err, "unable to retrieve rows affected")
|
||||
} else if count == 0 {
|
||||
// Could not attach the file to the post
|
||||
return model.NewAppError("SqlFileInfoStore.AttachToPost",
|
||||
"store.sql_file_info.attach_to_post.app_error", nil, "post_id="+postId+", file_id="+fileId, http.StatusBadRequest)
|
||||
return store.NewErrInvalidInput("FileInfo", "<id, postId, creatorId>", fmt.Sprintf("<%s, %s, %s>", fileId, postId, creatorId))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fs SqlFileInfoStore) DeleteForPost(postId string) (string, *model.AppError) {
|
||||
func (fs SqlFileInfoStore) DeleteForPost(postId string) (string, error) {
|
||||
if _, err := fs.GetMaster().Exec(
|
||||
`UPDATE
|
||||
FileInfo
|
||||
@@ -265,25 +262,23 @@ func (fs SqlFileInfoStore) DeleteForPost(postId string) (string, *model.AppError
|
||||
DeleteAt = :DeleteAt
|
||||
WHERE
|
||||
PostId = :PostId`, map[string]interface{}{"DeleteAt": model.GetMillis(), "PostId": postId}); err != nil {
|
||||
return "", model.NewAppError("SqlFileInfoStore.DeleteForPost",
|
||||
"store.sql_file_info.delete_for_post.app_error", nil, "post_id="+postId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
return "", errors.Wrapf(err, "failed to update FileInfo with postId=%s", postId)
|
||||
}
|
||||
return postId, nil
|
||||
}
|
||||
|
||||
func (fs SqlFileInfoStore) PermanentDelete(fileId string) *model.AppError {
|
||||
func (fs SqlFileInfoStore) PermanentDelete(fileId string) error {
|
||||
if _, err := fs.GetMaster().Exec(
|
||||
`DELETE FROM
|
||||
FileInfo
|
||||
WHERE
|
||||
Id = :FileId`, map[string]interface{}{"FileId": fileId}); err != nil {
|
||||
return model.NewAppError("SqlFileInfoStore.PermanentDelete",
|
||||
"store.sql_file_info.permanent_delete.app_error", nil, "file_id="+fileId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
return errors.Wrapf(err, "failed to delete FileInfo with id=%s", fileId)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fs SqlFileInfoStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, *model.AppError) {
|
||||
func (fs SqlFileInfoStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, error) {
|
||||
var query string
|
||||
if fs.DriverName() == "postgres" {
|
||||
query = "DELETE from FileInfo WHERE Id = any (array (SELECT Id FROM FileInfo WHERE CreateAt < :EndTime LIMIT :Limit))"
|
||||
@@ -293,28 +288,28 @@ func (fs SqlFileInfoStore) PermanentDeleteBatch(endTime int64, limit int64) (int
|
||||
|
||||
sqlResult, err := fs.GetMaster().Exec(query, map[string]interface{}{"EndTime": endTime, "Limit": limit})
|
||||
if err != nil {
|
||||
return 0, model.NewAppError("SqlFileInfoStore.PermanentDeleteBatch", "store.sql_file_info.permanent_delete_batch.app_error", nil, ""+err.Error(), http.StatusInternalServerError)
|
||||
return 0, errors.Wrap(err, "failed to delete FileInfos in batch")
|
||||
}
|
||||
|
||||
rowsAffected, err := sqlResult.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, model.NewAppError("SqlFileInfoStore.PermanentDeleteBatch", "store.sql_file_info.permanent_delete_batch.app_error", nil, ""+err.Error(), http.StatusInternalServerError)
|
||||
return 0, errors.Wrapf(err, "unable to retrieve rows affected")
|
||||
}
|
||||
|
||||
return rowsAffected, nil
|
||||
}
|
||||
|
||||
func (fs SqlFileInfoStore) PermanentDeleteByUser(userId string) (int64, *model.AppError) {
|
||||
func (fs SqlFileInfoStore) PermanentDeleteByUser(userId string) (int64, error) {
|
||||
query := "DELETE from FileInfo WHERE CreatorId = :CreatorId"
|
||||
|
||||
sqlResult, err := fs.GetMaster().Exec(query, map[string]interface{}{"CreatorId": userId})
|
||||
if err != nil {
|
||||
return 0, model.NewAppError("SqlFileInfoStore.PermanentDeleteByUser", "store.sql_file_info.PermanentDeleteByUser.app_error", nil, ""+err.Error(), http.StatusInternalServerError)
|
||||
return 0, errors.Wrapf(err, "failed to delete FileInfo with creatorId=%s", userId)
|
||||
}
|
||||
|
||||
rowsAffected, err := sqlResult.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, model.NewAppError("SqlFileInfoStore.PermanentDeleteByUser", "store.sql_file_info.PermanentDeleteByUser.app_error", nil, ""+err.Error(), http.StatusInternalServerError)
|
||||
return 0, errors.Wrapf(err, "unable to retrieve rows affected")
|
||||
}
|
||||
|
||||
return rowsAffected, nil
|
||||
|
||||
@@ -534,18 +534,18 @@ type StatusStore interface {
|
||||
}
|
||||
|
||||
type FileInfoStore interface {
|
||||
Save(info *model.FileInfo) (*model.FileInfo, *model.AppError)
|
||||
Get(id string) (*model.FileInfo, *model.AppError)
|
||||
GetByPath(path string) (*model.FileInfo, *model.AppError)
|
||||
GetForPost(postId string, readFromMaster, includeDeleted, allowFromCache bool) ([]*model.FileInfo, *model.AppError)
|
||||
GetForUser(userId string) ([]*model.FileInfo, *model.AppError)
|
||||
GetWithOptions(page, perPage int, opt *model.GetFileInfosOptions) ([]*model.FileInfo, *model.AppError)
|
||||
Save(info *model.FileInfo) (*model.FileInfo, error)
|
||||
Get(id string) (*model.FileInfo, error)
|
||||
GetByPath(path string) (*model.FileInfo, error)
|
||||
GetForPost(postId string, readFromMaster, includeDeleted, allowFromCache bool) ([]*model.FileInfo, error)
|
||||
GetForUser(userId string) ([]*model.FileInfo, error)
|
||||
GetWithOptions(page, perPage int, opt *model.GetFileInfosOptions) ([]*model.FileInfo, error)
|
||||
InvalidateFileInfosForPostCache(postId string, deleted bool)
|
||||
AttachToPost(fileId string, postId string, creatorId string) *model.AppError
|
||||
DeleteForPost(postId string) (string, *model.AppError)
|
||||
PermanentDelete(fileId string) *model.AppError
|
||||
PermanentDeleteBatch(endTime int64, limit int64) (int64, *model.AppError)
|
||||
PermanentDeleteByUser(userId string) (int64, *model.AppError)
|
||||
AttachToPost(fileId string, postId string, creatorId string) error
|
||||
DeleteForPost(postId string) (string, error)
|
||||
PermanentDelete(fileId string) error
|
||||
PermanentDeleteBatch(endTime int64, limit int64) (int64, error)
|
||||
PermanentDeleteByUser(userId string) (int64, error)
|
||||
ClearCaches()
|
||||
}
|
||||
|
||||
|
||||
@@ -15,16 +15,14 @@ type FileInfoStore struct {
|
||||
}
|
||||
|
||||
// AttachToPost provides a mock function with given fields: fileId, postId, creatorId
|
||||
func (_m *FileInfoStore) AttachToPost(fileId string, postId string, creatorId string) *model.AppError {
|
||||
func (_m *FileInfoStore) AttachToPost(fileId string, postId string, creatorId string) error {
|
||||
ret := _m.Called(fileId, postId, creatorId)
|
||||
|
||||
var r0 *model.AppError
|
||||
if rf, ok := ret.Get(0).(func(string, string, string) *model.AppError); ok {
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(string, string, string) error); ok {
|
||||
r0 = rf(fileId, postId, creatorId)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.AppError)
|
||||
}
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
@@ -36,7 +34,7 @@ func (_m *FileInfoStore) ClearCaches() {
|
||||
}
|
||||
|
||||
// DeleteForPost provides a mock function with given fields: postId
|
||||
func (_m *FileInfoStore) DeleteForPost(postId string) (string, *model.AppError) {
|
||||
func (_m *FileInfoStore) DeleteForPost(postId string) (string, error) {
|
||||
ret := _m.Called(postId)
|
||||
|
||||
var r0 string
|
||||
@@ -46,20 +44,18 @@ func (_m *FileInfoStore) DeleteForPost(postId string) (string, *model.AppError)
|
||||
r0 = ret.Get(0).(string)
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string) error); ok {
|
||||
r1 = rf(postId)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// Get provides a mock function with given fields: id
|
||||
func (_m *FileInfoStore) Get(id string) (*model.FileInfo, *model.AppError) {
|
||||
func (_m *FileInfoStore) Get(id string) (*model.FileInfo, error) {
|
||||
ret := _m.Called(id)
|
||||
|
||||
var r0 *model.FileInfo
|
||||
@@ -71,20 +67,18 @@ func (_m *FileInfoStore) Get(id string) (*model.FileInfo, *model.AppError) {
|
||||
}
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string) error); ok {
|
||||
r1 = rf(id)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetByPath provides a mock function with given fields: path
|
||||
func (_m *FileInfoStore) GetByPath(path string) (*model.FileInfo, *model.AppError) {
|
||||
func (_m *FileInfoStore) GetByPath(path string) (*model.FileInfo, error) {
|
||||
ret := _m.Called(path)
|
||||
|
||||
var r0 *model.FileInfo
|
||||
@@ -96,20 +90,18 @@ func (_m *FileInfoStore) GetByPath(path string) (*model.FileInfo, *model.AppErro
|
||||
}
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string) error); ok {
|
||||
r1 = rf(path)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetForPost provides a mock function with given fields: postId, readFromMaster, includeDeleted, allowFromCache
|
||||
func (_m *FileInfoStore) GetForPost(postId string, readFromMaster bool, includeDeleted bool, allowFromCache bool) ([]*model.FileInfo, *model.AppError) {
|
||||
func (_m *FileInfoStore) GetForPost(postId string, readFromMaster bool, includeDeleted bool, allowFromCache bool) ([]*model.FileInfo, error) {
|
||||
ret := _m.Called(postId, readFromMaster, includeDeleted, allowFromCache)
|
||||
|
||||
var r0 []*model.FileInfo
|
||||
@@ -121,20 +113,18 @@ func (_m *FileInfoStore) GetForPost(postId string, readFromMaster bool, includeD
|
||||
}
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string, bool, bool, bool) *model.AppError); ok {
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string, bool, bool, bool) error); ok {
|
||||
r1 = rf(postId, readFromMaster, includeDeleted, allowFromCache)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetForUser provides a mock function with given fields: userId
|
||||
func (_m *FileInfoStore) GetForUser(userId string) ([]*model.FileInfo, *model.AppError) {
|
||||
func (_m *FileInfoStore) GetForUser(userId string) ([]*model.FileInfo, error) {
|
||||
ret := _m.Called(userId)
|
||||
|
||||
var r0 []*model.FileInfo
|
||||
@@ -146,20 +136,18 @@ func (_m *FileInfoStore) GetForUser(userId string) ([]*model.FileInfo, *model.Ap
|
||||
}
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string) error); ok {
|
||||
r1 = rf(userId)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetWithOptions provides a mock function with given fields: page, perPage, opt
|
||||
func (_m *FileInfoStore) GetWithOptions(page int, perPage int, opt *model.GetFileInfosOptions) ([]*model.FileInfo, *model.AppError) {
|
||||
func (_m *FileInfoStore) GetWithOptions(page int, perPage int, opt *model.GetFileInfosOptions) ([]*model.FileInfo, error) {
|
||||
ret := _m.Called(page, perPage, opt)
|
||||
|
||||
var r0 []*model.FileInfo
|
||||
@@ -171,13 +159,11 @@ func (_m *FileInfoStore) GetWithOptions(page int, perPage int, opt *model.GetFil
|
||||
}
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(int, int, *model.GetFileInfosOptions) *model.AppError); ok {
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(int, int, *model.GetFileInfosOptions) error); ok {
|
||||
r1 = rf(page, perPage, opt)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
@@ -189,23 +175,21 @@ func (_m *FileInfoStore) InvalidateFileInfosForPostCache(postId string, deleted
|
||||
}
|
||||
|
||||
// PermanentDelete provides a mock function with given fields: fileId
|
||||
func (_m *FileInfoStore) PermanentDelete(fileId string) *model.AppError {
|
||||
func (_m *FileInfoStore) PermanentDelete(fileId string) error {
|
||||
ret := _m.Called(fileId)
|
||||
|
||||
var r0 *model.AppError
|
||||
if rf, ok := ret.Get(0).(func(string) *model.AppError); ok {
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(string) error); ok {
|
||||
r0 = rf(fileId)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.AppError)
|
||||
}
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// PermanentDeleteBatch provides a mock function with given fields: endTime, limit
|
||||
func (_m *FileInfoStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, *model.AppError) {
|
||||
func (_m *FileInfoStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, error) {
|
||||
ret := _m.Called(endTime, limit)
|
||||
|
||||
var r0 int64
|
||||
@@ -215,20 +199,18 @@ func (_m *FileInfoStore) PermanentDeleteBatch(endTime int64, limit int64) (int64
|
||||
r0 = ret.Get(0).(int64)
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(int64, int64) *model.AppError); ok {
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(int64, int64) error); ok {
|
||||
r1 = rf(endTime, limit)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// PermanentDeleteByUser provides a mock function with given fields: userId
|
||||
func (_m *FileInfoStore) PermanentDeleteByUser(userId string) (int64, *model.AppError) {
|
||||
func (_m *FileInfoStore) PermanentDeleteByUser(userId string) (int64, error) {
|
||||
ret := _m.Called(userId)
|
||||
|
||||
var r0 int64
|
||||
@@ -238,20 +220,18 @@ func (_m *FileInfoStore) PermanentDeleteByUser(userId string) (int64, *model.App
|
||||
r0 = ret.Get(0).(int64)
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string) error); ok {
|
||||
r1 = rf(userId)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// Save provides a mock function with given fields: info
|
||||
func (_m *FileInfoStore) Save(info *model.FileInfo) (*model.FileInfo, *model.AppError) {
|
||||
func (_m *FileInfoStore) Save(info *model.FileInfo) (*model.FileInfo, error) {
|
||||
ret := _m.Called(info)
|
||||
|
||||
var r0 *model.FileInfo
|
||||
@@ -263,13 +243,11 @@ func (_m *FileInfoStore) Save(info *model.FileInfo) (*model.FileInfo, *model.App
|
||||
}
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(*model.FileInfo) *model.AppError); ok {
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(*model.FileInfo) error); ok {
|
||||
r1 = rf(info)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
|
||||
@@ -2625,7 +2625,7 @@ func (s *TimerLayerEmojiStore) Search(name string, prefixOnly bool, limit int) (
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerFileInfoStore) AttachToPost(fileId string, postId string, creatorId string) *model.AppError {
|
||||
func (s *TimerLayerFileInfoStore) AttachToPost(fileId string, postId string, creatorId string) error {
|
||||
start := timemodule.Now()
|
||||
|
||||
err := s.FileInfoStore.AttachToPost(fileId, postId, creatorId)
|
||||
@@ -2656,7 +2656,7 @@ func (s *TimerLayerFileInfoStore) ClearCaches() {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *TimerLayerFileInfoStore) DeleteForPost(postId string) (string, *model.AppError) {
|
||||
func (s *TimerLayerFileInfoStore) DeleteForPost(postId string) (string, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.FileInfoStore.DeleteForPost(postId)
|
||||
@@ -2672,7 +2672,7 @@ func (s *TimerLayerFileInfoStore) DeleteForPost(postId string) (string, *model.A
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerFileInfoStore) Get(id string) (*model.FileInfo, *model.AppError) {
|
||||
func (s *TimerLayerFileInfoStore) Get(id string) (*model.FileInfo, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.FileInfoStore.Get(id)
|
||||
@@ -2688,7 +2688,7 @@ func (s *TimerLayerFileInfoStore) Get(id string) (*model.FileInfo, *model.AppErr
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerFileInfoStore) GetByPath(path string) (*model.FileInfo, *model.AppError) {
|
||||
func (s *TimerLayerFileInfoStore) GetByPath(path string) (*model.FileInfo, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.FileInfoStore.GetByPath(path)
|
||||
@@ -2704,7 +2704,7 @@ func (s *TimerLayerFileInfoStore) GetByPath(path string) (*model.FileInfo, *mode
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerFileInfoStore) GetForPost(postId string, readFromMaster bool, includeDeleted bool, allowFromCache bool) ([]*model.FileInfo, *model.AppError) {
|
||||
func (s *TimerLayerFileInfoStore) GetForPost(postId string, readFromMaster bool, includeDeleted bool, allowFromCache bool) ([]*model.FileInfo, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.FileInfoStore.GetForPost(postId, readFromMaster, includeDeleted, allowFromCache)
|
||||
@@ -2720,7 +2720,7 @@ func (s *TimerLayerFileInfoStore) GetForPost(postId string, readFromMaster bool,
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerFileInfoStore) GetForUser(userId string) ([]*model.FileInfo, *model.AppError) {
|
||||
func (s *TimerLayerFileInfoStore) GetForUser(userId string) ([]*model.FileInfo, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.FileInfoStore.GetForUser(userId)
|
||||
@@ -2736,7 +2736,7 @@ func (s *TimerLayerFileInfoStore) GetForUser(userId string) ([]*model.FileInfo,
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerFileInfoStore) GetWithOptions(page int, perPage int, opt *model.GetFileInfosOptions) ([]*model.FileInfo, *model.AppError) {
|
||||
func (s *TimerLayerFileInfoStore) GetWithOptions(page int, perPage int, opt *model.GetFileInfosOptions) ([]*model.FileInfo, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.FileInfoStore.GetWithOptions(page, perPage, opt)
|
||||
@@ -2767,7 +2767,7 @@ func (s *TimerLayerFileInfoStore) InvalidateFileInfosForPostCache(postId string,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *TimerLayerFileInfoStore) PermanentDelete(fileId string) *model.AppError {
|
||||
func (s *TimerLayerFileInfoStore) PermanentDelete(fileId string) error {
|
||||
start := timemodule.Now()
|
||||
|
||||
err := s.FileInfoStore.PermanentDelete(fileId)
|
||||
@@ -2783,7 +2783,7 @@ func (s *TimerLayerFileInfoStore) PermanentDelete(fileId string) *model.AppError
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *TimerLayerFileInfoStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, *model.AppError) {
|
||||
func (s *TimerLayerFileInfoStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.FileInfoStore.PermanentDeleteBatch(endTime, limit)
|
||||
@@ -2799,7 +2799,7 @@ func (s *TimerLayerFileInfoStore) PermanentDeleteBatch(endTime int64, limit int6
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerFileInfoStore) PermanentDeleteByUser(userId string) (int64, *model.AppError) {
|
||||
func (s *TimerLayerFileInfoStore) PermanentDeleteByUser(userId string) (int64, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.FileInfoStore.PermanentDeleteByUser(userId)
|
||||
@@ -2815,7 +2815,7 @@ func (s *TimerLayerFileInfoStore) PermanentDeleteByUser(userId string) (int64, *
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerFileInfoStore) Save(info *model.FileInfo) (*model.FileInfo, *model.AppError) {
|
||||
func (s *TimerLayerFileInfoStore) Save(info *model.FileInfo) (*model.FileInfo, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.FileInfoStore.Save(info)
|
||||
|
||||
Ссылка в новой задаче
Block a user