Browse Source

音视频搜索空

kobe6258 6 months ago
parent
commit
94cb8b97d2
1 changed files with 6 additions and 5 deletions
  1. 6 5
      models/media/media.go

+ 6 - 5
models/media/media.go

@@ -63,13 +63,14 @@ func GetCountByMediaType(mediaType string) (count int64, latestId int64) {
 
 func GetCountByMediaTypeByAnalystId(mediaType string, analystId int) (count int64, latestId int64) {
 	db := models.Main()
-	var ids []int
-	err := db.Model(&Media{}).Select("id").Where("media_type = ? and deleted = ? and author_id = ?", mediaType, false, analystId).Order("id desc").Scan(&ids).Error
+	err := db.Model(&Media{}).Select("id").Where("media_type = ? and deleted = ? and author_id = ?", mediaType, false, analystId).Count(&count).Error
 	if err != nil {
-		return 0, 0
+		return
+	}
+	err = db.Model(&Media{}).Select("Max(id)").Where("media_type = ? and deleted = ? and author_id = ?", mediaType, false, analystId).Scan(&latestId).Error
+	if err != nil {
+		return
 	}
-	count = int64(len(ids))
-	latestId = int64(ids[0])
 	return
 }
 func GetMediaPage(latestId int64, limit int, offset int, mediaType string) (mediaList []Media, err error) {