loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: check for webauthn in 2fa user search (#6726)

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6726
Reviewed-by: Otto <otto@codeberg.org>

Otto 2ba8946c 59dfab2d

+5 -7
+4 -6
models/user/search.go
··· 127 127 return e.Where(cond) 128 128 } 129 129 130 - // 2fa filter uses LEFT JOIN to check whether a user has a 2fa record 131 - // While using LEFT JOIN, sometimes the performance might not be good, but it won't be a problem now, such SQL is seldom executed. 132 - // There are some possible methods to refactor this SQL in future when we really need to optimize the performance (but not now): 133 - // (1) add a column in user table (2) add a setting value in user_setting table (3) use search engines (bleve/elasticsearch) 130 + // Check if the user has two factor enabled, which is TOTP or Webauthn. 134 131 if opts.IsTwoFactorEnabled.Value() { 135 - cond = cond.And(builder.Expr("two_factor.uid IS NOT NULL")) 132 + cond = cond.And(builder.Expr("two_factor.uid IS NOT NULL OR webauthn_credential.user_id IS NOT NULL")) 136 133 } else { 137 - cond = cond.And(builder.Expr("two_factor.uid IS NULL")) 134 + cond = cond.And(builder.Expr("two_factor.uid IS NULL AND webauthn_credential.user_id IS NULL")) 138 135 } 139 136 140 137 return e.Join("LEFT OUTER", "two_factor", "two_factor.uid = `user`.id"). 138 + Join("LEFT OUTER", "webauthn_credential", "webauthn_credential.user_id = `user`.id"). 141 139 Where(cond) 142 140 } 143 141
+1 -1
models/user/user_test.go
··· 222 222 []int64{1041, 37}) 223 223 224 224 testUserSuccess(&user_model.SearchUserOptions{ListOptions: db.ListOptions{Page: 1}, IsTwoFactorEnabled: optional.Some(true)}, 225 - []int64{24}) 225 + []int64{24, 32}) 226 226 } 227 227 228 228 func TestEmailNotificationPreferences(t *testing.T) {