⬆️ Use faster way to check attachment it exists

This commit is contained in:
2024-05-18 16:59:58 +08:00
parent 827423ae3f
commit 7d36755a72
6 changed files with 17 additions and 15 deletions

View File

@@ -18,3 +18,12 @@ func GetAttachmentByUUID(uuid string) (*pcpb.Attachment, error) {
Uuid: &uuid,
})
}
func CheckAttachmentByUUIDExists(uuid string, usage string) bool {
_, err := grpc.Attachments.CheckAttachmentExists(context.Background(), &pcpb.AttachmentLookupRequest{
Uuid: &uuid,
Usage: &usage,
})
return err == nil
}

View File

@@ -55,13 +55,10 @@ func GetPostWithAlias(alias string, ignoreLimitation ...bool) (models.Post, erro
if err := tx.
Where("alias = ?", alias).
Preload("Author").
Preload("Attachments").
Preload("ReplyTo").
Preload("ReplyTo.Author").
Preload("ReplyTo.Attachments").
Preload("RepostTo").
Preload("RepostTo.Author").
Preload("RepostTo.Attachments").
First(&item).Error; err != nil {
return item, err
}
@@ -79,13 +76,10 @@ func GetPost(id uint, ignoreLimitation ...bool) (models.Post, error) {
if err := tx.
Where("id = ?", id).
Preload("Author").
Preload("Attachments").
Preload("ReplyTo").
Preload("ReplyTo.Author").
Preload("ReplyTo.Attachments").
Preload("RepostTo").
Preload("RepostTo.Author").
Preload("RepostTo.Attachments").
First(&item).Error; err != nil {
return item, err
}
@@ -157,13 +151,10 @@ func ListPost(tx *gorm.DB, take int, offset int, noReact ...bool) ([]models.Post
Limit(take).Offset(offset).
Order("created_at DESC").
Preload("Author").
Preload("Attachments").
Preload("ReplyTo").
Preload("ReplyTo.Author").
Preload("ReplyTo.Attachments").
Preload("RepostTo").
Preload("RepostTo.Author").
Preload("RepostTo.Attachments").
Find(&items).Error; err != nil {
return items, err
}