@@ -29,6 +29,7 @@ import (
29
29
"code.gitea.io/gitea/modules/validation"
30
30
31
31
"xorm.io/builder"
32
+ "xorm.io/xorm"
32
33
)
33
34
34
35
// UserType defines the user type
@@ -309,14 +310,27 @@ func (u *User) GenerateEmailActivateCode(email string) string {
309
310
return code
310
311
}
311
312
312
- // GetUserFollowers returns range of user's followers.
313
- func GetUserFollowers (ctx context.Context , u , viewer * User , listOptions db.ListOptions ) ([]* User , int64 , error ) {
314
- sess := db .GetEngine (ctx ).
313
+ func searchUserFollowers (ctx context.Context , u , viewer * User ) * xorm.Session {
314
+ return db .GetEngine (ctx ).
315
315
Select ("`user`.*" ).
316
316
Join ("LEFT" , "follow" , "`user`.id=follow.user_id" ).
317
317
Where ("follow.follow_id=?" , u .ID ).
318
318
And ("`user`.type=?" , UserTypeIndividual ).
319
319
And (isUserVisibleToViewerCond (viewer ))
320
+ }
321
+
322
+ func searchUserFollowing (ctx context.Context , u , viewer * User ) * xorm.Session {
323
+ return db .GetEngine (db .DefaultContext ).
324
+ Select ("`user`.*" ).
325
+ Join ("LEFT" , "follow" , "`user`.id=follow.follow_id" ).
326
+ Where ("follow.user_id=?" , u .ID ).
327
+ And ("`user`.type IN (?, ?)" , UserTypeIndividual , UserTypeOrganization ).
328
+ And (isUserVisibleToViewerCond (viewer ))
329
+ }
330
+
331
+ // GetUserFollowers returns range of user's followers.
332
+ func GetUserFollowers (ctx context.Context , u , viewer * User , listOptions db.ListOptions ) ([]* User , int64 , error ) {
333
+ sess := searchUserFollowers (ctx , u , viewer )
320
334
321
335
if listOptions .Page != 0 {
322
336
sess = db .SetSessionPagination (sess , & listOptions )
@@ -333,12 +347,7 @@ func GetUserFollowers(ctx context.Context, u, viewer *User, listOptions db.ListO
333
347
334
348
// GetUserFollowing returns range of user's following.
335
349
func GetUserFollowing (ctx context.Context , u , viewer * User , listOptions db.ListOptions ) ([]* User , int64 , error ) {
336
- sess := db .GetEngine (db .DefaultContext ).
337
- Select ("`user`.*" ).
338
- Join ("LEFT" , "follow" , "`user`.id=follow.follow_id" ).
339
- Where ("follow.user_id=?" , u .ID ).
340
- And ("`user`.type IN (?, ?)" , UserTypeIndividual , UserTypeOrganization ).
341
- And (isUserVisibleToViewerCond (viewer ))
350
+ sess := searchUserFollowing (ctx , u , viewer )
342
351
343
352
if listOptions .Page != 0 {
344
353
sess = db .SetSessionPagination (sess , & listOptions )
@@ -354,41 +363,15 @@ func GetUserFollowing(ctx context.Context, u, viewer *User, listOptions db.ListO
354
363
}
355
364
356
365
// GetUserFollowersCount returns count of user's followers.
357
- func GetUserFollowersCount (ctx context.Context , u , viewer * User , listOptions db.ListOptions ) (int64 , error ) {
358
- sess := db .GetEngine (ctx ).
359
- Select ("`user`.*" ).
360
- Join ("LEFT" , "follow" , "`user`.id=follow.user_id" ).
361
- Where ("follow.follow_id=?" , u .ID ).
362
- And ("`user`.type=?" , UserTypeIndividual ).
363
- And (isUserVisibleToViewerCond (viewer ))
364
-
365
- if listOptions .Page != 0 {
366
- sess = db .SetSessionPagination (sess , & listOptions )
367
- count , err := sess .Count ()
368
- return count , err
369
- }
370
-
371
- count , err := sess .Count ()
372
- return count , err
366
+ func GetUserFollowersCount (ctx context.Context , u , viewer * User ) (int64 , error ) {
367
+ sess := searchUserFollowers (ctx , u , viewer )
368
+ return sess .Count ()
373
369
}
374
370
375
371
// GetUserFollowingCount returns count of user's following.
376
- func GetUserFollowingCount (ctx context.Context , u , viewer * User , listOptions db.ListOptions ) (int64 , error ) {
377
- sess := db .GetEngine (db .DefaultContext ).
378
- Select ("`user`.*" ).
379
- Join ("LEFT" , "follow" , "`user`.id=follow.follow_id" ).
380
- Where ("follow.user_id=?" , u .ID ).
381
- And ("`user`.type IN (?, ?)" , UserTypeIndividual , UserTypeOrganization ).
382
- And (isUserVisibleToViewerCond (viewer ))
383
-
384
- if listOptions .Page != 0 {
385
- sess = db .SetSessionPagination (sess , & listOptions )
386
- count , err := sess .Count ()
387
- return count , err
388
- }
389
-
390
- count , err := sess .Count ()
391
- return count , err
372
+ func GetUserFollowingCount (ctx context.Context , u , viewer * User ) (int64 , error ) {
373
+ sess := searchUserFollowing (ctx , u , viewer )
374
+ return sess .Count ()
392
375
}
393
376
394
377
// NewGitSig generates and returns the signature of given user.
0 commit comments