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

          Line data    Source code
       1             : // Copyright (C) 2017 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.group;
      16             : 
      17             : import static com.google.common.base.Preconditions.checkState;
      18             : import static com.google.gerrit.server.query.group.GroupQueryBuilder.FIELD_LIMIT;
      19             : 
      20             : import com.google.gerrit.entities.InternalGroup;
      21             : import com.google.gerrit.index.IndexConfig;
      22             : import com.google.gerrit.index.query.AndSource;
      23             : import com.google.gerrit.index.query.IndexPredicate;
      24             : import com.google.gerrit.index.query.Predicate;
      25             : import com.google.gerrit.index.query.QueryProcessor;
      26             : import com.google.gerrit.metrics.MetricMaker;
      27             : import com.google.gerrit.server.CurrentUser;
      28             : import com.google.gerrit.server.account.AccountLimits;
      29             : import com.google.gerrit.server.account.GroupControl;
      30             : import com.google.gerrit.server.index.group.GroupIndexCollection;
      31             : import com.google.gerrit.server.index.group.GroupIndexRewriter;
      32             : import com.google.gerrit.server.index.group.GroupSchemaDefinitions;
      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 group 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 GroupQueryProcessor extends QueryProcessor<InternalGroup> {
      44             :   private final Provider<CurrentUser> userProvider;
      45             :   private final GroupControl.GenericFactory groupControlFactory;
      46             :   private final Sequences sequences;
      47             :   private final IndexConfig indexConfig;
      48             : 
      49             :   static {
      50             :     // It is assumed that basic rewrites do not touch visibleto predicates.
      51         150 :     checkState(
      52         150 :         !GroupIsVisibleToPredicate.class.isAssignableFrom(IndexPredicate.class),
      53             :         "GroupQueryProcessor assumes visibleto is not used by the index rewriter.");
      54         150 :   }
      55             : 
      56             :   @Inject
      57             :   protected GroupQueryProcessor(
      58             :       Provider<CurrentUser> userProvider,
      59             :       AccountLimits.Factory limitsFactory,
      60             :       MetricMaker metricMaker,
      61             :       IndexConfig indexConfig,
      62             :       GroupIndexCollection indexes,
      63             :       GroupIndexRewriter rewriter,
      64             :       GroupControl.GenericFactory groupControlFactory,
      65             :       Sequences sequences) {
      66         150 :     super(
      67             :         metricMaker,
      68             :         GroupSchemaDefinitions.INSTANCE,
      69             :         indexConfig,
      70             :         indexes,
      71             :         rewriter,
      72             :         FIELD_LIMIT,
      73          12 :         () -> limitsFactory.create(userProvider.get()).getQueryLimit());
      74         150 :     this.userProvider = userProvider;
      75         150 :     this.groupControlFactory = groupControlFactory;
      76         150 :     this.sequences = sequences;
      77         150 :     this.indexConfig = indexConfig;
      78         150 :   }
      79             : 
      80             :   @Override
      81             :   protected Predicate<InternalGroup> enforceVisibility(Predicate<InternalGroup> pred) {
      82          12 :     return new AndSource<>(
      83             :         pred,
      84          12 :         new GroupIsVisibleToPredicate(groupControlFactory, userProvider.get()),
      85             :         start,
      86             :         indexConfig);
      87             :   }
      88             : 
      89             :   @Override
      90             :   protected String formatForLogging(InternalGroup internalGroup) {
      91          26 :     return internalGroup.getGroupUUID().get();
      92             :   }
      93             : 
      94             :   @Override
      95             :   protected int getIndexSize() {
      96           0 :     return sequences.lastGroupId();
      97             :   }
      98             : 
      99             :   @Override
     100             :   protected int getBatchSize() {
     101           0 :     return sequences.groupBatchSize();
     102             :   }
     103             : }

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