[server] Add option to updateMetadata without versionChange (#1708)

## Description

## Tests
This commit is contained in:
Neeraj Gupta 2024-05-13 13:31:58 +05:30 committed by GitHub
commit 50613b8c57
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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
type UpdateMultipleMagicMetadataRequest struct {
MetadataList []UpdateMagicMetadata `json:"metadataList" binding:"required"`
SkipVersion *bool `json:"skipVersion"`
}
// 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 {
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 {
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
// 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()
tx, err := repo.DB.BeginTx(ctx, nil)
if err != nil {
@ -336,6 +341,9 @@ func (repo *FileRepository) UpdateMagicAttributes(ctx context.Context, fileUpdat
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}).
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,