🐛 Fix uploader still using old cache api

This commit is contained in:
LittleSheep 2024-08-21 21:32:06 +08:00
parent fea0664d62
commit 10eb0ba3bc
3 changed files with 8 additions and 11 deletions

View File

@ -4,9 +4,10 @@
<option name="autoReloadType" value="ALL" /> <option name="autoReloadType" value="ALL" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="18dd0d68-b4b8-40db-9734-9119b5c848bd" name="更改" comment=":bug: Fix analyzer didn't cache attachment"> <list default="true" id="18dd0d68-b4b8-40db-9734-9119b5c848bd" name="更改" comment=":bug: Fix direct upload will save as non-uploaded">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/server/api/up_direct_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/up_direct_api.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pkg/internal/services/attachments.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/attachments.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/services/uploader.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/uploader.go" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -117,7 +118,6 @@
</option> </option>
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<MESSAGE value=":arrow_up: Upgrade Passport to fix bug" />
<MESSAGE value=":ambulance: Fix getting user panic" /> <MESSAGE value=":ambulance: Fix getting user panic" />
<MESSAGE value=":zap: Add cache into metadata fetching" /> <MESSAGE value=":zap: Add cache into metadata fetching" />
<MESSAGE value=":recycle: Moved onto dealer" /> <MESSAGE value=":recycle: Moved onto dealer" />
@ -142,7 +142,8 @@
<MESSAGE value=":sparkles: Make it more implementable" /> <MESSAGE value=":sparkles: Make it more implementable" />
<MESSAGE value=":bug: Fix merged file isn't add to cache" /> <MESSAGE value=":bug: Fix merged file isn't add to cache" />
<MESSAGE value=":bug: Fix analyzer didn't cache attachment" /> <MESSAGE value=":bug: Fix analyzer didn't cache attachment" />
<option name="LAST_COMMIT_MESSAGE" value=":bug: Fix analyzer didn't cache attachment" /> <MESSAGE value=":bug: Fix direct upload will save as non-uploaded" />
<option name="LAST_COMMIT_MESSAGE" value=":bug: Fix direct upload will save as non-uploaded" />
</component> </component>
<component name="VgoProject"> <component name="VgoProject">
<settings-migrated>true</settings-migrated> <settings-migrated>true</settings-migrated>

View File

@ -31,7 +31,6 @@ func GetAttachmentByID(id uint) (models.Attachment, error) {
}).Preload("Pool").Preload("Account").First(&attachment).Error; err != nil { }).Preload("Pool").Preload("Account").First(&attachment).Error; err != nil {
return attachment, err return attachment, err
} else { } else {
MaintainAttachmentCache()
CacheAttachment(attachment) CacheAttachment(attachment)
} }
@ -49,7 +48,6 @@ func GetAttachmentByRID(rid string) (models.Attachment, error) {
}).Preload("Pool").Preload("Account").First(&attachment).Error; err != nil { }).Preload("Pool").Preload("Account").First(&attachment).Error; err != nil {
return attachment, err return attachment, err
} else { } else {
MaintainAttachmentCache()
CacheAttachment(attachment) CacheAttachment(attachment)
} }
@ -74,6 +72,7 @@ func GetAttachmentCache(id any) (models.Attachment, bool) {
} }
func CacheAttachment(item models.Attachment) { func CacheAttachment(item models.Attachment) {
MaintainAttachmentCache()
metadataCache.Store(item.Rid, item) metadataCache.Store(item.Rid, item)
} }
@ -110,7 +109,6 @@ func NewAttachmentMetadata(tx *gorm.DB, user models.Account, file *multipart.Fil
if err := tx.Save(&attachment).Error; err != nil { if err := tx.Save(&attachment).Error; err != nil {
return attachment, fmt.Errorf("failed to save attachment record: %v", err) return attachment, fmt.Errorf("failed to save attachment record: %v", err)
} else { } else {
MaintainAttachmentCache()
CacheAttachment(attachment) CacheAttachment(attachment)
} }
@ -142,7 +140,6 @@ func NewAttachmentPlaceholder(tx *gorm.DB, user models.Account, attachment model
if err := tx.Save(&attachment).Error; err != nil { if err := tx.Save(&attachment).Error; err != nil {
return attachment, fmt.Errorf("failed to save attachment record: %v", err) return attachment, fmt.Errorf("failed to save attachment record: %v", err)
} else { } else {
MaintainAttachmentCache()
CacheAttachment(attachment) CacheAttachment(attachment)
} }
@ -189,7 +186,6 @@ func UpdateAttachment(item models.Attachment) (models.Attachment, error) {
if err := database.C.Updates(&item).Error; err != nil { if err := database.C.Updates(&item).Error; err != nil {
return item, err return item, err
} else { } else {
MaintainAttachmentCache()
CacheAttachment(item) CacheAttachment(item)
} }

View File

@ -113,7 +113,7 @@ func ReUploadFileToPermanent(meta models.Attachment) error {
} }
database.C.Save(&meta) database.C.Save(&meta)
metadataCache.Store(meta.ID, meta) CacheAttachment(meta)
return nil return nil
case models.DestinationTypeS3: case models.DestinationTypeS3:
var destConfigured models.S3Destination var destConfigured models.S3Destination
@ -137,7 +137,7 @@ func ReUploadFileToPermanent(meta models.Attachment) error {
} }
database.C.Save(&meta) database.C.Save(&meta)
metadataCache.Store(meta.ID, meta) CacheAttachment(meta)
return nil return nil
default: default:
return fmt.Errorf("invalid destination: unsupported protocol %s", dest.Type) return fmt.Errorf("invalid destination: unsupported protocol %s", dest.Type)