💥 Replace attachment id by rid when fetching

This commit is contained in:
2024-08-18 21:10:10 +08:00
parent e92e5bad60
commit 165a6be985
4 changed files with 18 additions and 39 deletions

View File

@ -22,11 +22,6 @@ const metadataCacheLimit = 512
var metadataCache sync.Map
func GetAttachmentByID(id uint) (models.Attachment, error) {
strId := strconv.Itoa(int(id))
if val, ok := metadataCache.Load(strId); ok && val.(models.Attachment).Account.ID > 0 {
return val.(models.Attachment), nil
}
var attachment models.Attachment
if err := database.C.Where(models.Attachment{
BaseModel: models.BaseModel{ID: id},
@ -68,17 +63,14 @@ func GetAttachmentByHash(hash string) (models.Attachment, error) {
return attachment, nil
}
func GetAttachmentCache(id uint) (models.Attachment, bool) {
strId := strconv.Itoa(int(id))
if val, ok := metadataCache.Load(strId); ok && val.(models.Attachment).Account.ID > 0 {
func GetAttachmentCache(id any) (models.Attachment, bool) {
if val, ok := metadataCache.Load(id); ok && val.(models.Attachment).Account.ID > 0 {
return val.(models.Attachment), ok
}
return models.Attachment{}, false
}
func CacheAttachment(item models.Attachment) {
strId := strconv.Itoa(int(item.ID))
metadataCache.Store(strId, item)
metadataCache.Store(item.Rid, item)
}