@@ -243,7 +243,11 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, int64, err
243243 sess := db .GetEngine (ctx ).Where (cond )
244244 sess = db .SetSessionPagination (sess , & opts )
245245
246- count , err = sess .Desc ("`action`.created_unix" ).FindAndCount (& actions )
246+ if opts .DontCount {
247+ err = sess .Desc ("`action`.created_unix" ).Find (& actions )
248+ } else {
249+ count , err = sess .Desc ("`action`.created_unix" ).FindAndCount (& actions )
250+ }
247251 if err != nil {
248252 return nil , 0 , fmt .Errorf ("FindAndCount: %w" , err )
249253 }
@@ -257,11 +261,13 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, int64, err
257261 return nil , 0 , fmt .Errorf ("Find(actionsIDs): %w" , err )
258262 }
259263
260- count , err = db .GetEngine (ctx ).Where (cond ).
261- Table ("action" ).
262- Cols ("`action`.id" ).Count ()
263- if err != nil {
264- return nil , 0 , fmt .Errorf ("Count: %w" , err )
264+ if ! opts .DontCount {
265+ count , err = db .GetEngine (ctx ).Where (cond ).
266+ Table ("action" ).
267+ Cols ("`action`.id" ).Count ()
268+ if err != nil {
269+ return nil , 0 , fmt .Errorf ("Count: %w" , err )
270+ }
265271 }
266272
267273 if err := db .GetEngine (ctx ).In ("`action`.id" , actionIDs ).Desc ("`action`.created_unix" ).Find (& actions ); err != nil {
@@ -275,3 +281,9 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, int64, err
275281
276282 return actions , count , nil
277283}
284+
285+ func CountUserFeeds (ctx context.Context , userID int64 ) (int64 , error ) {
286+ return db .GetEngine (ctx ).Where ("user_id = ?" , userID ).
287+ And ("is_deleted = ?" , false ).
288+ Count (& Action {})
289+ }
0 commit comments