[server] Add option to updateMetadata without versionChange

This commit is contained in:
Neeraj Gupta 2024-05-11 13:31:46 +05:30
parent 6f82881ac3
commit 6a186ef420
3 changed files with 11 additions and 2 deletions

View file

@ -134,6 +134,7 @@ type UpdateMagicMetadata struct {
// UpdateMultipleMagicMetadataRequest request payload for updating magic metadata for list of files // UpdateMultipleMagicMetadataRequest request payload for updating magic metadata for list of files
type UpdateMultipleMagicMetadataRequest struct { type UpdateMultipleMagicMetadataRequest struct {
MetadataList []UpdateMagicMetadata `json:"metadataList" binding:"required"` MetadataList []UpdateMagicMetadata `json:"metadataList" binding:"required"`
SkipVersion *bool `json:"skipVersion"`
} }
// UploadURL represents the upload url for a specific object // UploadURL represents the upload url for a specific object

View file

@ -502,7 +502,7 @@ func (c *FileController) UpdateMagicMetadata(ctx *gin.Context, req ente.UpdateMu
if err != nil { if err != nil {
return stacktrace.Propagate(err, "") return stacktrace.Propagate(err, "")
} }
err = c.FileRepo.UpdateMagicAttributes(ctx, req.MetadataList, isPublicMetadata) err = c.FileRepo.UpdateMagicAttributes(ctx, req.MetadataList, isPublicMetadata, req.SkipVersion)
if err != nil { if err != nil {
return stacktrace.Propagate(err, "failed to update magic attributes") return stacktrace.Propagate(err, "failed to update magic attributes")
} }

View file

@ -311,7 +311,12 @@ func (repo *FileRepository) Update(file ente.File, fileSize int64, thumbnailSize
// UpdateMagicAttributes updates the magic attributes for the list of files and update collection_files & collection // UpdateMagicAttributes updates the magic attributes for the list of files and update collection_files & collection
// which have this file. // which have this file.
func (repo *FileRepository) UpdateMagicAttributes(ctx context.Context, fileUpdates []ente.UpdateMagicMetadata, isPublicMetadata bool) error { func (repo *FileRepository) UpdateMagicAttributes(
ctx context.Context,
fileUpdates []ente.UpdateMagicMetadata,
isPublicMetadata bool,
skipVersion *bool,
) error {
updationTime := time.Microseconds() updationTime := time.Microseconds()
tx, err := repo.DB.BeginTx(ctx, nil) tx, err := repo.DB.BeginTx(ctx, nil)
if err != nil { if err != nil {
@ -336,6 +341,9 @@ func (repo *FileRepository) UpdateMagicAttributes(ctx context.Context, fileUpdat
return stacktrace.Propagate(err, "") return stacktrace.Propagate(err, "")
} }
} }
if skipVersion != nil && *skipVersion {
return tx.Commit()
}
// todo: full table scan, need to add index (for discussion: add user_id and idx {user_id, file_id}). // todo: full table scan, need to add index (for discussion: add user_id and idx {user_id, file_id}).
updatedRows, err := tx.QueryContext(ctx, `UPDATE collection_files updatedRows, err := tx.QueryContext(ctx, `UPDATE collection_files
SET updation_time = $1 WHERE file_id = ANY($2) AND is_deleted= false RETURNING collection_id`, updationTime, SET updation_time = $1 WHERE file_id = ANY($2) AND is_deleted= false RETURNING collection_id`, updationTime,