Remove AccountAccess.byPreferredEmail
BecomeAnyAccountLoginServlet was the last user of AccountAccess.byPreferredEmail. Instead of going to ReviewDb to lookup accounts by preferred email, it's now doing a lookup from the account index. This is a preparation for migrating the accounts to NoteDb, because then we can no longer lookup accounts by prefered email from ReviewDb. Change-Id: I371f5791455435faf47764c684377304ebf02ff0 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
parent
e12c306ca3
commit
8562864736
@ -44,6 +44,7 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Writer;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
@ -215,8 +216,15 @@ class BecomeAnyAccountLoginServlet extends HttpServlet {
|
||||
|
||||
private AuthResult byPreferredEmail(String email) {
|
||||
try (ReviewDb db = schema.open()) {
|
||||
List<Account> matches = db.accounts().byPreferredEmail(email).toList();
|
||||
return matches.size() == 1 ? auth(matches.get(0)) : null;
|
||||
Optional<Account> match =
|
||||
accountQuery
|
||||
.byPreferredEmail(email)
|
||||
.stream()
|
||||
// the index query also matches prefixes, filter those out
|
||||
.filter(a -> email.equalsIgnoreCase(a.getAccount().getPreferredEmail()))
|
||||
.map(AccountState::getAccount)
|
||||
.findFirst();
|
||||
return match.isPresent() ? auth(match.get()) : null;
|
||||
} catch (OrmException e) {
|
||||
getServletContext().log("cannot query database", e);
|
||||
return null;
|
||||
|
@ -28,9 +28,6 @@ public interface AccountAccess extends Access<Account, Account.Id> {
|
||||
@PrimaryKey("accountId")
|
||||
Account get(Account.Id key) throws OrmException;
|
||||
|
||||
@Query("WHERE preferredEmail = ? LIMIT 2")
|
||||
ResultSet<Account> byPreferredEmail(String email) throws OrmException;
|
||||
|
||||
@Query("ORDER BY accountId")
|
||||
ResultSet<Account> all() throws OrmException;
|
||||
}
|
||||
|
@ -4,13 +4,6 @@
|
||||
-- Indexes to support @Query
|
||||
--
|
||||
|
||||
-- *********************************************************************
|
||||
-- AccountAccess
|
||||
-- covers: byPreferredEmail
|
||||
CREATE INDEX accounts_byPreferredEmail
|
||||
ON accounts (preferred_email);
|
||||
|
||||
|
||||
-- *********************************************************************
|
||||
-- AccountGroupMemberAccess
|
||||
-- @PrimaryKey covers: byAccount
|
||||
|
@ -5,14 +5,6 @@ delimiter #
|
||||
-- Indexes to support @Query
|
||||
--
|
||||
|
||||
-- *********************************************************************
|
||||
-- AccountAccess
|
||||
-- covers: byPreferredEmail
|
||||
CREATE INDEX accounts_byPreferredEmail
|
||||
ON accounts (preferred_email)
|
||||
#
|
||||
|
||||
|
||||
-- *********************************************************************
|
||||
-- AccountGroupMemberAccess
|
||||
-- @PrimaryKey covers: byAccount
|
||||
|
@ -51,13 +51,6 @@ delimiter ;
|
||||
-- Indexes to support @Query
|
||||
--
|
||||
|
||||
-- *********************************************************************
|
||||
-- AccountAccess
|
||||
-- covers: byPreferredEmail
|
||||
CREATE INDEX accounts_byPreferredEmail
|
||||
ON accounts (preferred_email);
|
||||
|
||||
|
||||
-- *********************************************************************
|
||||
-- AccountGroupMemberAccess
|
||||
-- @PrimaryKey covers: byAccount
|
||||
|
@ -35,7 +35,7 @@ import java.util.concurrent.TimeUnit;
|
||||
/** A version of the database schema. */
|
||||
public abstract class SchemaVersion {
|
||||
/** The current schema version. */
|
||||
public static final Class<Schema_156> C = Schema_156.class;
|
||||
public static final Class<Schema_157> C = Schema_157.class;
|
||||
|
||||
public static int getBinaryVersion() {
|
||||
return guessVersion(C);
|
||||
|
@ -0,0 +1,41 @@
|
||||
// Copyright (C) 2017 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.schema;
|
||||
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gwtorm.jdbc.JdbcSchema;
|
||||
import com.google.gwtorm.schema.sql.SqlDialect;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.StatementExecutor;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/** Drop unused indexes from accounts table. */
|
||||
public class Schema_157 extends SchemaVersion {
|
||||
@Inject
|
||||
Schema_157(Provider<Schema_156> prior) {
|
||||
super(prior);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
|
||||
JdbcSchema schema = (JdbcSchema) db;
|
||||
SqlDialect dialect = schema.getDialect();
|
||||
try (StatementExecutor e = newExecutor(db)) {
|
||||
dialect.dropIndex(e, "accounts", "accounts_byPreferredEmail");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user