From 2d76de2574d2e3734ed8e566845042e6fb281a6e Mon Sep 17 00:00:00 2001 From: Unknwon Date: Tue, 26 Jul 2016 17:26:48 +0800 Subject: #3281 fix x.Iterate returns nothing inside session scope with SQLite3 --- models/user.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'models/user.go') diff --git a/models/user.go b/models/user.go index a22162dc2d..5e9b60addb 100644 --- a/models/user.go +++ b/models/user.go @@ -768,10 +768,13 @@ func deleteUser(e *xorm.Session, u *User) error { if err = e.Find(&keys, &PublicKey{OwnerID: u.ID}); err != nil { return fmt.Errorf("get all public keys: %v", err) } - for _, key := range keys { - if err = deletePublicKey(e, key.ID); err != nil { - return fmt.Errorf("deletePublicKey: %v", err) - } + + keyIDs := make([]int64, len(keys)) + for i := range keys { + keyIDs[i] = keys[i].ID + } + if err = deletePublicKeys(e, keyIDs...); err != nil { + return fmt.Errorf("deletePublicKeys: %v", err) } // ***** END: PublicKey ***** @@ -788,7 +791,6 @@ func deleteUser(e *xorm.Session, u *User) error { // Note: There are something just cannot be roll back, // so just keep error logs of those operations. - RewriteAllPublicKeys() os.RemoveAll(UserPath(u.Name)) os.Remove(u.CustomAvatarPath()) @@ -809,15 +811,20 @@ func DeleteUser(u *User) (err error) { return err } - return sess.Commit() + if err = sess.Commit(); err != nil { + return err + } + + return RewriteAllPublicKeys() } // DeleteInactivateUsers deletes all inactivate users and email addresses. func DeleteInactivateUsers() (err error) { users := make([]*User, 0, 10) - if err = x.Where("is_active=?", false).Find(&users); err != nil { + if err = x.Where("is_active = ?", false).Find(&users); err != nil { return fmt.Errorf("get all inactive users: %v", err) } + // FIXME: should only update authorized_keys file once after all deletions. for _, u := range users { if err = DeleteUser(u); err != nil { // Ignore users that were set inactive by admin. @@ -828,7 +835,7 @@ func DeleteInactivateUsers() (err error) { } } - _, err = x.Where("is_activated=?", false).Delete(new(EmailAddress)) + _, err = x.Where("is_activated = ?", false).Delete(new(EmailAddress)) return err } -- cgit v1.2.3