🐛 Add limitation of pagination

This commit is contained in:
LittleSheep 2024-02-12 12:32:37 +08:00
parent 5ec6cacb69
commit c5ed5e8df6

View File

@ -79,6 +79,10 @@ WHERE t.id = ?`, prefix, prefix, prefix), post.ID).Scan(&reactInfo)
} }
func ListPost(tx *gorm.DB, take int, offset int) ([]*models.Post, error) { func ListPost(tx *gorm.DB, take int, offset int) ([]*models.Post, error) {
if take > 20 {
take = 20
}
var posts []*models.Post var posts []*models.Post
if err := PreloadRelatedPost(tx). if err := PreloadRelatedPost(tx).
Limit(take). Limit(take).