MCPcopy Create free account
hub / github.com/gogs/gogs / recountFollows

Method recountFollows

internal/database/users.go:585–626  ·  view source on GitHub ↗
(tx *gorm.DB, userID, followID int64)

Source from the content-addressed store, hash-verified

583}
584
585func (*UsersStore) recountFollows(tx *gorm.DB, userID, followID int64) error {
586 /*
587 Equivalent SQL for PostgreSQL:
588
589 UPDATE "user"
590 SET num_followers = (
591 SELECT COUNT(*) FROM follow WHERE follow_id = @followID
592 )
593 WHERE id = @followID
594 */
595 err := tx.Model(&User{}).
596 Where("id = ?", followID).
597 Update(
598 "num_followers",
599 tx.Model(&Follow{}).Select("COUNT(*)").Where("follow_id = ?", followID),
600 ).
601 Error
602 if err != nil {
603 return errors.Wrap(err, `update "user.num_followers"`)
604 }
605
606 /*
607 Equivalent SQL for PostgreSQL:
608
609 UPDATE "user"
610 SET num_following = (
611 SELECT COUNT(*) FROM follow WHERE user_id = @userID
612 )
613 WHERE id = @userID
614 */
615 err = tx.Model(&User{}).
616 Where("id = ?", userID).
617 Update(
618 "num_following",
619 tx.Model(&Follow{}).Select("COUNT(*)").Where("user_id = ?", userID),
620 ).
621 Error
622 if err != nil {
623 return errors.Wrap(err, `update "user.num_following"`)
624 }
625 return nil
626}
627
628// Follow marks the user to follow the other user.
629func (s *UsersStore) Follow(ctx context.Context, userID, followID int64) error {

Callers 2

FollowMethod · 0.95
UnfollowMethod · 0.95

Calls 2

WhereMethod · 0.80
UpdateMethod · 0.65

Tested by

no test coverage detected