LCOV - code coverage report
Current view: top level - server/query/account - AccountQueryProcessor.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 12 14 85.7 %
Date: 2022-11-19 15:00:39 Functions: 5 7 71.4 %

          Line data    Source code
       1             : // Copyright (C) 2016 The Android Open Source Project
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License");
       4             : // you may not use this file except in compliance with the License.
       5             : // You may obtain a copy of the License at
       6             : //
       7             : // http://www.apache.org/licenses/LICENSE-2.0
       8             : //
       9             : // Unless required by applicable law or agreed to in writing, software
      10             : // distributed under the License is distributed on an "AS IS" BASIS,
      11             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             : // See the License for the specific language governing permissions and
      13             : // limitations under the License.
      14             : 
      15             : package com.google.gerrit.server.query.account;
      16             : 
      17             : import static com.google.common.base.Preconditions.checkState;
      18             : import static com.google.gerrit.server.query.account.AccountQueryBuilder.FIELD_LIMIT;
      19             : 
      20             : import com.google.gerrit.index.IndexConfig;
      21             : import com.google.gerrit.index.query.AndSource;
      22             : import com.google.gerrit.index.query.IndexPredicate;
      23             : import com.google.gerrit.index.query.Predicate;
      24             : import com.google.gerrit.index.query.QueryProcessor;
      25             : import com.google.gerrit.metrics.MetricMaker;
      26             : import com.google.gerrit.server.CurrentUser;
      27             : import com.google.gerrit.server.account.AccountControl;
      28             : import com.google.gerrit.server.account.AccountLimits;
      29             : import com.google.gerrit.server.account.AccountState;
      30             : import com.google.gerrit.server.index.account.AccountIndexCollection;
      31             : import com.google.gerrit.server.index.account.AccountIndexRewriter;
      32             : import com.google.gerrit.server.index.account.AccountSchemaDefinitions;
      33             : import com.google.gerrit.server.notedb.Sequences;
      34             : import com.google.inject.Inject;
      35             : import com.google.inject.Provider;
      36             : 
      37             : /**
      38             :  * Query processor for the account index.
      39             :  *
      40             :  * <p>Instances are one-time-use. Other singleton classes should inject a Provider rather than
      41             :  * holding on to a single instance.
      42             :  */
      43             : public class AccountQueryProcessor extends QueryProcessor<AccountState> {
      44             :   private final AccountControl.Factory accountControlFactory;
      45             :   private final Sequences sequences;
      46             :   private final IndexConfig indexConfig;
      47             : 
      48             :   static {
      49             :     // It is assumed that basic rewrites do not touch visibleto predicates.
      50         109 :     checkState(
      51         109 :         !AccountIsVisibleToPredicate.class.isAssignableFrom(IndexPredicate.class),
      52             :         "AccountQueryProcessor assumes visibleto is not used by the index rewriter.");
      53         109 :   }
      54             : 
      55             :   @Inject
      56             :   protected AccountQueryProcessor(
      57             :       Provider<CurrentUser> userProvider,
      58             :       AccountLimits.Factory limitsFactory,
      59             :       MetricMaker metricMaker,
      60             :       IndexConfig indexConfig,
      61             :       AccountIndexCollection indexes,
      62             :       AccountIndexRewriter rewriter,
      63             :       AccountControl.Factory accountControlFactory,
      64             :       Sequences sequences) {
      65         109 :     super(
      66             :         metricMaker,
      67             :         AccountSchemaDefinitions.INSTANCE,
      68             :         indexConfig,
      69             :         indexes,
      70             :         rewriter,
      71             :         FIELD_LIMIT,
      72          36 :         () -> limitsFactory.create(userProvider.get()).getQueryLimit());
      73         109 :     this.accountControlFactory = accountControlFactory;
      74         109 :     this.sequences = sequences;
      75         109 :     this.indexConfig = indexConfig;
      76         109 :   }
      77             : 
      78             :   @Override
      79             :   protected Predicate<AccountState> enforceVisibility(Predicate<AccountState> pred) {
      80          36 :     return new AndSource<>(
      81          36 :         pred, new AccountIsVisibleToPredicate(accountControlFactory.get()), start, indexConfig);
      82             :   }
      83             : 
      84             :   @Override
      85             :   protected String formatForLogging(AccountState accountState) {
      86          11 :     return accountState.account().id().toString();
      87             :   }
      88             : 
      89             :   @Override
      90             :   protected int getIndexSize() {
      91           0 :     return sequences.lastAccountId();
      92             :   }
      93             : 
      94             :   @Override
      95             :   protected int getBatchSize() {
      96           0 :     return sequences.accountBatchSize();
      97             :   }
      98             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750