mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-26 23:09:28 +00:00
Remove unnecessary loads in org_team (#1090)
This commit is contained in:
parent
22f7aa6e9c
commit
d21d5fd736
|
@ -330,46 +330,40 @@ func DeleteTeam(t *Team) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get organization.
|
|
||||||
org, err := GetUserByID(t.OrgID)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
sess := x.NewSession()
|
sess := x.NewSession()
|
||||||
defer sessionRelease(sess)
|
defer sessionRelease(sess)
|
||||||
if err = sess.Begin(); err != nil {
|
if err := sess.Begin(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete all accesses.
|
// Delete all accesses.
|
||||||
for _, repo := range t.Repos {
|
for _, repo := range t.Repos {
|
||||||
if err = repo.recalculateTeamAccesses(sess, t.ID); err != nil {
|
if err := repo.recalculateTeamAccesses(sess, t.ID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete team-repo
|
// Delete team-repo
|
||||||
if _, err = sess.
|
if _, err := sess.
|
||||||
Where("team_id=?", t.ID).
|
Where("team_id=?", t.ID).
|
||||||
Delete(new(TeamRepo)); err != nil {
|
Delete(new(TeamRepo)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete team-user.
|
// Delete team-user.
|
||||||
if _, err = sess.
|
if _, err := sess.
|
||||||
Where("org_id=?", org.ID).
|
Where("org_id=?", t.OrgID).
|
||||||
Where("team_id=?", t.ID).
|
Where("team_id=?", t.ID).
|
||||||
Delete(new(TeamUser)); err != nil {
|
Delete(new(TeamUser)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete team.
|
// Delete team.
|
||||||
if _, err = sess.Id(t.ID).Delete(new(Team)); err != nil {
|
if _, err := sess.Id(t.ID).Delete(new(Team)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Update organization number of teams.
|
// Update organization number of teams.
|
||||||
if _, err = sess.Exec("UPDATE `user` SET num_teams=num_teams-1 WHERE id=?", t.OrgID); err != nil {
|
if _, err := sess.Exec("UPDATE `user` SET num_teams=num_teams-1 WHERE id=?", t.OrgID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -517,12 +511,6 @@ func removeTeamMember(e Engine, team *Team, userID int64) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get organization.
|
|
||||||
org, err := getUserByID(e, team.OrgID)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := e.Delete(&TeamUser{
|
if _, err := e.Delete(&TeamUser{
|
||||||
UID: userID,
|
UID: userID,
|
||||||
OrgID: team.OrgID,
|
OrgID: team.OrgID,
|
||||||
|
@ -538,16 +526,16 @@ func removeTeamMember(e Engine, team *Team, userID int64) error {
|
||||||
|
|
||||||
// Delete access to team repositories.
|
// Delete access to team repositories.
|
||||||
for _, repo := range team.Repos {
|
for _, repo := range team.Repos {
|
||||||
if err = repo.recalculateTeamAccesses(e, 0); err != nil {
|
if err := repo.recalculateTeamAccesses(e, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This must exist.
|
// This must exist.
|
||||||
ou := new(OrgUser)
|
ou := new(OrgUser)
|
||||||
_, err = e.
|
_, err := e.
|
||||||
Where("uid = ?", userID).
|
Where("uid = ?", userID).
|
||||||
And("org_id = ?", org.ID).
|
And("org_id = ?", team.OrgID).
|
||||||
Get(ou)
|
Get(ou)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue