Index account on creation
Change-Id: I16cdc920cbc2dbdff70fb0fae4d5ac2a8c2d3b5b Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -38,6 +38,7 @@ import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.CreateAccount.Input;
|
||||
import com.google.gerrit.server.api.accounts.AccountExternalIdCreator;
|
||||
import com.google.gerrit.server.group.GroupsCollection;
|
||||
import com.google.gerrit.server.index.account.AccountIndexer;
|
||||
import com.google.gerrit.server.ssh.SshKeyCache;
|
||||
import com.google.gwtorm.server.OrmDuplicateKeyException;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
@@ -77,6 +78,7 @@ public class CreateAccount implements RestModifyView<TopLevelResource, Input> {
|
||||
private final VersionedAuthorizedKeys.Accessor authorizedKeys;
|
||||
private final SshKeyCache sshKeyCache;
|
||||
private final AccountCache accountCache;
|
||||
private final AccountIndexer indexer;
|
||||
private final AccountByEmailCache byEmailCache;
|
||||
private final AccountLoader.Factory infoLoader;
|
||||
private final DynamicSet<AccountExternalIdCreator> externalIdCreators;
|
||||
@@ -90,6 +92,7 @@ public class CreateAccount implements RestModifyView<TopLevelResource, Input> {
|
||||
VersionedAuthorizedKeys.Accessor authorizedKeys,
|
||||
SshKeyCache sshKeyCache,
|
||||
AccountCache accountCache,
|
||||
AccountIndexer indexer,
|
||||
AccountByEmailCache byEmailCache,
|
||||
AccountLoader.Factory infoLoader,
|
||||
DynamicSet<AccountExternalIdCreator> externalIdCreators,
|
||||
@@ -101,6 +104,7 @@ public class CreateAccount implements RestModifyView<TopLevelResource, Input> {
|
||||
this.authorizedKeys = authorizedKeys;
|
||||
this.sshKeyCache = sshKeyCache;
|
||||
this.accountCache = accountCache;
|
||||
this.indexer = indexer;
|
||||
this.byEmailCache = byEmailCache;
|
||||
this.infoLoader = infoLoader;
|
||||
this.externalIdCreators = externalIdCreators;
|
||||
@@ -205,6 +209,7 @@ public class CreateAccount implements RestModifyView<TopLevelResource, Input> {
|
||||
|
||||
accountCache.evictByUsername(username);
|
||||
byEmailCache.evict(input.email);
|
||||
indexer.index(id);
|
||||
|
||||
AccountLoader loader = infoLoader.create(true);
|
||||
AccountInfo info = loader.get(id);
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.google.gerrit.server.git.WorkQueue;
|
||||
import com.google.gerrit.server.index.account.AccountIndexCollection;
|
||||
import com.google.gerrit.server.index.account.AccountIndexDefinition;
|
||||
import com.google.gerrit.server.index.account.AccountIndexRewriter;
|
||||
import com.google.gerrit.server.index.account.AccountIndexer;
|
||||
import com.google.gerrit.server.index.account.AccountSchemaDefinitions;
|
||||
import com.google.gerrit.server.index.change.ChangeIndexCollection;
|
||||
import com.google.gerrit.server.index.change.ChangeIndexDefinition;
|
||||
@@ -91,6 +92,7 @@ public class IndexModule extends LifecycleModule {
|
||||
bind(AccountIndexRewriter.class);
|
||||
bind(AccountIndexCollection.class);
|
||||
listener().to(AccountIndexCollection.class);
|
||||
factory(AccountIndexer.Factory.class);
|
||||
|
||||
bind(ChangeIndexRewriter.class);
|
||||
bind(ChangeIndexCollection.class);
|
||||
@@ -128,6 +130,13 @@ public class IndexModule extends LifecycleModule {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
AccountIndexer getAccountIndexer(AccountIndexer.Factory factory,
|
||||
AccountIndexCollection indexes) {
|
||||
return factory.create(indexes);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
ChangeIndexer getChangeIndexer(
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
// Copyright (C) 2016 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.index.account;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.server.account.AccountCache;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.index.Index;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.google.inject.assistedinject.AssistedInject;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class AccountIndexer {
|
||||
|
||||
public interface Factory {
|
||||
AccountIndexer create(AccountIndexCollection indexes);
|
||||
}
|
||||
|
||||
private final AccountIndexCollection indexes;
|
||||
private final AccountCache byIdCache;
|
||||
|
||||
@AssistedInject
|
||||
AccountIndexer(AccountCache byIdCache,
|
||||
@Assisted AccountIndexCollection indexes) {
|
||||
this.byIdCache = byIdCache;
|
||||
this.indexes = indexes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronously index an account.
|
||||
*
|
||||
* @param id account id to index.
|
||||
*/
|
||||
public void index(Account.Id id) throws IOException {
|
||||
for (Index<?, AccountState> i : indexes.getWriteIndexes()) {
|
||||
i.replace(byIdCache.get(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user