Skip to content

Commit d21d5fd

Browse files
ethantkoeniglunny
authored andcommitted
Remove unnecessary loads in org_team (#1090)
1 parent 22f7aa6 commit d21d5fd

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

models/org_team.go

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -330,46 +330,40 @@ func DeleteTeam(t *Team) error {
330330
return err
331331
}
332332

333-
// Get organization.
334-
org, err := GetUserByID(t.OrgID)
335-
if err != nil {
336-
return err
337-
}
338-
339333
sess := x.NewSession()
340334
defer sessionRelease(sess)
341-
if err = sess.Begin(); err != nil {
335+
if err := sess.Begin(); err != nil {
342336
return err
343337
}
344338

345339
// Delete all accesses.
346340
for _, repo := range t.Repos {
347-
if err = repo.recalculateTeamAccesses(sess, t.ID); err != nil {
341+
if err := repo.recalculateTeamAccesses(sess, t.ID); err != nil {
348342
return err
349343
}
350344
}
351345

352346
// Delete team-repo
353-
if _, err = sess.
347+
if _, err := sess.
354348
Where("team_id=?", t.ID).
355349
Delete(new(TeamRepo)); err != nil {
356350
return err
357351
}
358352

359353
// Delete team-user.
360-
if _, err = sess.
361-
Where("org_id=?", org.ID).
354+
if _, err := sess.
355+
Where("org_id=?", t.OrgID).
362356
Where("team_id=?", t.ID).
363357
Delete(new(TeamUser)); err != nil {
364358
return err
365359
}
366360

367361
// Delete team.
368-
if _, err = sess.Id(t.ID).Delete(new(Team)); err != nil {
362+
if _, err := sess.Id(t.ID).Delete(new(Team)); err != nil {
369363
return err
370364
}
371365
// Update organization number of teams.
372-
if _, err = sess.Exec("UPDATE `user` SET num_teams=num_teams-1 WHERE id=?", t.OrgID); err != nil {
366+
if _, err := sess.Exec("UPDATE `user` SET num_teams=num_teams-1 WHERE id=?", t.OrgID); err != nil {
373367
return err
374368
}
375369

@@ -517,12 +511,6 @@ func removeTeamMember(e Engine, team *Team, userID int64) error {
517511
return err
518512
}
519513

520-
// Get organization.
521-
org, err := getUserByID(e, team.OrgID)
522-
if err != nil {
523-
return err
524-
}
525-
526514
if _, err := e.Delete(&TeamUser{
527515
UID: userID,
528516
OrgID: team.OrgID,
@@ -538,16 +526,16 @@ func removeTeamMember(e Engine, team *Team, userID int64) error {
538526

539527
// Delete access to team repositories.
540528
for _, repo := range team.Repos {
541-
if err = repo.recalculateTeamAccesses(e, 0); err != nil {
529+
if err := repo.recalculateTeamAccesses(e, 0); err != nil {
542530
return err
543531
}
544532
}
545533

546534
// This must exist.
547535
ou := new(OrgUser)
548-
_, err = e.
536+
_, err := e.
549537
Where("uid = ?", userID).
550-
And("org_id = ?", org.ID).
538+
And("org_id = ?", team.OrgID).
551539
Get(ou)
552540
if err != nil {
553541
return err

0 commit comments

Comments
 (0)