💥 Replace attachment id by rid when fetching
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user