Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop column NumFollowers and NumFollowing #24676

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
68 changes: 0 additions & 68 deletions models/fixtures/user.yml
Expand Up @@ -26,8 +26,6 @@
avatar: avatar1
avatar_email: user1@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 0
num_teams: 0
Expand Down Expand Up @@ -63,8 +61,6 @@
avatar: avatar2
avatar_email: user2@example.com
use_custom_avatar: false
num_followers: 2
num_following: 1
num_stars: 2
num_repos: 13
num_teams: 0
Expand Down Expand Up @@ -100,8 +96,6 @@
avatar: avatar3
avatar_email: user3@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 3
num_teams: 5
Expand Down Expand Up @@ -137,8 +131,6 @@
avatar: avatar4
avatar_email: user4@example.com
use_custom_avatar: false
num_followers: 0
num_following: 1
num_stars: 0
num_repos: 0
num_teams: 0
Expand Down Expand Up @@ -174,8 +166,6 @@
avatar: avatar5
avatar_email: user5@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 1
num_teams: 0
Expand Down Expand Up @@ -211,8 +201,6 @@
avatar: avatar6
avatar_email: user6@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 0
num_teams: 2
Expand Down Expand Up @@ -248,8 +236,6 @@
avatar: avatar7
avatar_email: user7@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 0
num_teams: 1
Expand Down Expand Up @@ -285,8 +271,6 @@
avatar: avatar8
avatar_email: user8@example.com
use_custom_avatar: false
num_followers: 1
num_following: 1
num_stars: 0
num_repos: 0
num_teams: 0
Expand Down Expand Up @@ -322,8 +306,6 @@
avatar: avatar9
avatar_email: user9@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 0
num_teams: 0
Expand Down Expand Up @@ -359,8 +341,6 @@
avatar: avatar10
avatar_email: user10@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 3
num_teams: 0
Expand Down Expand Up @@ -396,8 +376,6 @@
avatar: avatar11
avatar_email: user11@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 1
num_teams: 0
Expand Down Expand Up @@ -433,8 +411,6 @@
avatar: avatar12
avatar_email: user12@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 1
num_teams: 0
Expand Down Expand Up @@ -470,8 +446,6 @@
avatar: avatar13
avatar_email: user13@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 1
num_teams: 0
Expand Down Expand Up @@ -507,8 +481,6 @@
avatar: avatar14
avatar_email: user13@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 3
num_teams: 0
Expand Down Expand Up @@ -544,8 +516,6 @@
avatar: avatar15
avatar_email: user15@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 4
num_teams: 0
Expand Down Expand Up @@ -581,8 +551,6 @@
avatar: avatar16
avatar_email: user16@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 2
num_teams: 0
Expand Down Expand Up @@ -618,8 +586,6 @@
avatar: avatar17
avatar_email: user17@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 2
num_teams: 3
Expand Down Expand Up @@ -655,8 +621,6 @@
avatar: avatar18
avatar_email: user18@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 0
num_teams: 0
Expand Down Expand Up @@ -692,8 +656,6 @@
avatar: avatar19
avatar_email: user19@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 2
num_teams: 1
Expand Down Expand Up @@ -729,8 +691,6 @@
avatar: avatar20
avatar_email: user20@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 4
num_teams: 0
Expand Down Expand Up @@ -766,8 +726,6 @@
avatar: avatar21
avatar_email: user21@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 2
num_teams: 0
Expand Down Expand Up @@ -803,8 +761,6 @@
avatar: avatar22
avatar_email: limited_org@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 2
num_teams: 1
Expand Down Expand Up @@ -840,8 +796,6 @@
avatar: avatar23
avatar_email: privated_org@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 2
num_teams: 2
Expand Down Expand Up @@ -877,8 +831,6 @@
avatar: avatar24
avatar_email: user24@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 0
num_teams: 0
Expand Down Expand Up @@ -914,8 +866,6 @@
avatar: avatar25
avatar_email: org25@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 0
num_teams: 1
Expand Down Expand Up @@ -951,8 +901,6 @@
avatar: avatar26
avatar_email: org26@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 4
num_teams: 1
Expand Down Expand Up @@ -988,8 +936,6 @@
avatar: avatar27
avatar_email: user27@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 3
num_teams: 0
Expand Down Expand Up @@ -1025,8 +971,6 @@
avatar: avatar28
avatar_email: user28@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 0
num_teams: 0
Expand Down Expand Up @@ -1062,8 +1006,6 @@
avatar: avatar29
avatar_email: user29@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 0
num_teams: 0
Expand Down Expand Up @@ -1099,8 +1041,6 @@
avatar: avatar29
avatar_email: user30@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 4
num_teams: 0
Expand Down Expand Up @@ -1136,8 +1076,6 @@
avatar: avatar31
avatar_email: user31@example.com
use_custom_avatar: false
num_followers: 0
num_following: 1
num_stars: 0
num_repos: 0
num_teams: 0
Expand Down Expand Up @@ -1173,8 +1111,6 @@
avatar: avatar32
avatar_email: user30@example.com
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 0
num_teams: 0
Expand Down Expand Up @@ -1210,8 +1146,6 @@
avatar: avatar33
avatar_email: user33@example.com
use_custom_avatar: false
num_followers: 1
num_following: 0
num_stars: 0
num_repos: 0
num_teams: 0
Expand Down Expand Up @@ -1248,8 +1182,6 @@
avatar: avatar34
avatar_email: user34@example.com
use_custom_avatar: true
num_followers: 0
num_following: 0
num_stars: 0
num_repos: 0
num_teams: 0
Expand Down
6 changes: 4 additions & 2 deletions models/migrations/migrations.go
Expand Up @@ -494,15 +494,17 @@ var migrations = []Migration{
NewMigration("Add is_internal column to package", v1_20.AddIsInternalColumnToPackage),
// v257 -> v258
NewMigration("Add Actions Artifact table", v1_20.CreateActionArtifactTable),
// v258 -> 259
// v258 -> v259
NewMigration("Add PinOrder Column", v1_20.AddPinOrderToIssue),
// v259 -> 260
// v259 -> v260
NewMigration("Convert scoped access tokens", v1_20.ConvertScopedAccessTokens),

// Gitea 1.20.0 ends at 260

// v260 -> v261
NewMigration("Drop custom_labels column of action_runner table", v1_21.DropCustomLabelsColumnOfActionRunner),
// v261 -> v262
NewMigration("Drop column NumFollowers and NumFollowing on User", v1_21.DropColumnNumFollowersAndNumFollowingOnUser),
}

// GetCurrentDBVersion returns the current db version
Expand Down
22 changes: 22 additions & 0 deletions models/migrations/v1_21/v261.go
@@ -0,0 +1,22 @@
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package v1_21 //nolint

import (
"code.gitea.io/gitea/models/migrations/base"

"xorm.io/xorm"
)

func DropColumnNumFollowersAndNumFollowingOnUser(x *xorm.Engine) error {
sess := x.NewSession()
defer sess.Close()
if err := sess.Begin(); err != nil {
return err
}
if err := base.DropTableColumns(sess, "user", "num_followers", "num_following"); err != nil {
return err
}
return sess.Commit()
}
2 changes: 0 additions & 2 deletions models/unittest/consistency.go
Expand Up @@ -69,8 +69,6 @@ func init() {
AssertCountByCond(t, "star", builder.Eq{"uid": user.int("ID")}, user.int("NumStars"))
AssertCountByCond(t, "org_user", builder.Eq{"org_id": user.int("ID")}, user.int("NumMembers"))
AssertCountByCond(t, "team", builder.Eq{"org_id": user.int("ID")}, user.int("NumTeams"))
AssertCountByCond(t, "follow", builder.Eq{"user_id": user.int("ID")}, user.int("NumFollowing"))
AssertCountByCond(t, "follow", builder.Eq{"follow_id": user.int("ID")}, user.int("NumFollowers"))
if user.int("Type") != modelsUserTypeOrganization {
assert.EqualValues(t, 0, user.int("NumMembers"), "Unexpected number of members for user id: %d", user.int("ID"))
assert.EqualValues(t, 0, user.int("NumTeams"), "Unexpected number of teams for user id: %d", user.int("ID"))
Expand Down
16 changes: 0 additions & 16 deletions models/user/follow.go
Expand Up @@ -41,14 +41,6 @@ func FollowUser(userID, followID int64) (err error) {
if err = db.Insert(ctx, &Follow{UserID: userID, FollowID: followID}); err != nil {
return err
}

if _, err = db.Exec(ctx, "UPDATE `user` SET num_followers = num_followers + 1 WHERE id = ?", followID); err != nil {
return err
}

if _, err = db.Exec(ctx, "UPDATE `user` SET num_following = num_following + 1 WHERE id = ?", userID); err != nil {
return err
}
return committer.Commit()
}

Expand All @@ -67,13 +59,5 @@ func UnfollowUser(userID, followID int64) (err error) {
if _, err = db.DeleteByBean(ctx, &Follow{UserID: userID, FollowID: followID}); err != nil {
return err
}

if _, err = db.Exec(ctx, "UPDATE `user` SET num_followers = num_followers - 1 WHERE id = ?", followID); err != nil {
return err
}

if _, err = db.Exec(ctx, "UPDATE `user` SET num_following = num_following - 1 WHERE id = ?", userID); err != nil {
return err
}
return committer.Commit()
}