|
@@ -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) {
|