MM-53747: Create job to encode older image paths (#24073)

Bifrost now encodes all image paths. Due to this
one-way translation, we need to encode all the older
image paths as well.

After this is done, we can remove the double-lookup.

https://mattermost.atlassian.net/browse/MM-53747

```release-note
NONE
```

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Agniva De Sarker
2023-07-25 08:38:35 +05:30
коммит произвёл GitHub
родитель 065d3c3f6b
Коммит 6d6e589c11
14 изменённых файлов: 399 добавлений и 28 удалений

Просмотреть файл

@@ -6,6 +6,7 @@ package app
import (
"context"
"fmt"
"os"
"reflect"
"github.com/mattermost/mattermost/server/public/model"
@@ -571,6 +572,35 @@ func (s *Server) doElasticsearchFixChannelIndex() {
}
}
func (s *Server) doCloudS3PathMigrations() {
// This migration is only applicable for cloud environments
if os.Getenv("MM_CLOUD_FILESTORE_BIFROST") == "" {
return
}
// If the migration is already marked as completed, don't do it again.
if _, err := s.Store().System().GetByName(model.MigrationKeyS3Path); err == nil {
return
}
// If there is a job already pending, no need to schedule again.
// This is possible if the pod was rolled over.
jobs, err := s.Store().Job().GetAllByTypeAndStatus(model.JobTypeS3PathMigration, model.JobStatusPending)
if err != nil {
mlog.Fatal("failed to get jobs by type and status", mlog.Err(err))
return
}
if len(jobs) > 0 {
return
}
if _, appErr := s.Jobs.CreateJob(model.JobTypeS3PathMigration, nil); appErr != nil {
mlog.Fatal("failed to start job for migrating s3 file paths", mlog.Err(appErr))
return
}
}
func (a *App) DoAppMigrations() {
a.Srv().doAppMigrations()
}
@@ -593,4 +623,5 @@ func (s *Server) doAppMigrations() {
s.doRemainingSchemaMigrations()
s.doPostPriorityConfigDefaultTrueMigration()
s.doElasticsearchFixChannelIndex()
s.doCloudS3PathMigrations()
}

Просмотреть файл

@@ -54,6 +54,7 @@ import (
"github.com/mattermost/mattermost/server/v8/channels/jobs/post_persistent_notifications"
"github.com/mattermost/mattermost/server/v8/channels/jobs/product_notices"
"github.com/mattermost/mattermost/server/v8/channels/jobs/resend_invitation_email"
"github.com/mattermost/mattermost/server/v8/channels/jobs/s3_path_migration"
"github.com/mattermost/mattermost/server/v8/channels/product"
"github.com/mattermost/mattermost/server/v8/channels/store"
"github.com/mattermost/mattermost/server/v8/channels/utils"
@@ -1568,6 +1569,11 @@ func (s *Server) initJobs() {
import_delete.MakeScheduler(s.Jobs),
)
s.Jobs.RegisterJobType(
model.JobTypeS3PathMigration,
s3_path_migration.MakeWorker(s.Jobs, s.Store(), s.FileBackend()),
nil)
s.Jobs.RegisterJobType(
model.JobTypeExportDelete,
export_delete.MakeWorker(s.Jobs, New(ServerConnector(s.Channels()))),