Skip to content

Commit

Permalink
Added global fetchSize variables to DAOs (#877)
Browse files Browse the repository at this point in the history
Added global fetchSize variables to JooqDao and appropriate DAOs
  • Loading branch information
zack-rma authored Dec 17, 2024
1 parent 0e97993 commit dc4e4fe
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
2 changes: 2 additions & 0 deletions cwms-data-api/src/main/java/cwms/cda/data/dao/JooqDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
public abstract class JooqDao<T> extends Dao<T> {
protected static final int ORACLE_CURSOR_TYPE = -10;
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
public static final int DEFAULT_FETCH_SIZE = 1000;
public static final int DEFAULT_SMALL_FETCH_SIZE = 500;

static ExecuteListener listener = new ExceptionWrappingListener();
private static Pattern INVALID_OFFICE_ID = Pattern.compile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public Optional<LocationGroup> getLocationGroup(@NotNull String officeId, @NotNu
.and(alcg.CAT_DB_OFFICE_ID.in(CWMS, officeId))
.and(assignmentOffice)
)
.orderBy(alga.ATTRIBUTE).fetchSize(1000).fetch(mapper);
.orderBy(alga.ATTRIBUTE).fetchSize(DEFAULT_FETCH_SIZE).fetch(mapper);

// Might want to verify that all the groups in the list are the same?
LocationGroup locGroup =
Expand Down Expand Up @@ -379,7 +379,7 @@ public List<LocationGroup> getLocationGroups(String locationOfficeId, String gro

Map<LocationGroup, List<AssignedLocation>> map = new LinkedHashMap<>();
connectBy.orderBy(alcg.LOC_CATEGORY_ID, alcg.LOC_GROUP_ID, alga.ATTRIBUTE)
.fetchSize(1000) // This made the query go from 2 minutes to 10 seconds?
.fetchSize(DEFAULT_FETCH_SIZE) // This made the query go from 2 minutes to 10 seconds?
.stream().map(mapper::map).forEach(pair -> {
LocationGroup locationGroup = pair.component1();
List<AssignedLocation> list = map.computeIfAbsent(locationGroup, k -> new ArrayList<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public List<Location> getLocations(String nameRegex, String unitSystem, String d
return dsl.select(AV_LOC.asterisk())
.from(AV_LOC)
.where(whereCondition)
.fetchSize(500)
.fetchSize(DEFAULT_SMALL_FETCH_SIZE)
.fetch(this::buildLocation);
}

Expand Down Expand Up @@ -291,7 +291,7 @@ public FeatureCollection buildFeatureCollection(String names, String units, Stri
selectQuery = selectQuery.and(AV_LOC.LOCATION_ID.in(identifiers));
}

List<Feature> features = selectQuery.fetchSize(500).stream()
List<Feature> features = selectQuery.fetchSize(DEFAULT_SMALL_FETCH_SIZE).stream()
.map(LocationsDaoImpl::buildFeatureFromAvLocRecord)
.collect(toList());
FeatureCollection collection = new FeatureCollection();
Expand Down Expand Up @@ -433,7 +433,7 @@ private Catalog getLocationCatalog(Catalog.CatalogPage catPage, int pageSize, Ca
.orderBy(avLoc2.DB_OFFICE_ID.asc(),limitId.asc(),avLoc2.ALIASED_ITEM.asc());
logger.log(Level.FINER, () -> query.getSQL(ParamType.INLINED));
List<? extends CatalogEntry> entries = query
.fetchSize(1000)
.fetchSize(DEFAULT_FETCH_SIZE)
.fetchStream()
.map(r -> r.into(AV_LOC2.AV_LOC2))
.collect(groupingBy(usace.cwms.db.jooq.codegen.tables.records.AV_LOC2::getLOCATION_CODE))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public Collection<RatingSpec> retrieveRatingSpecs(String office, String specIdMa
.leftOuterJoin(ratView)
.on(specView.RATING_SPEC_CODE.eq(ratView.RATING_SPEC_CODE))
.where(condition)
.fetchSize(1000);
.fetchSize(DEFAULT_FETCH_SIZE);

logger.fine(() -> query.getSQL(ParamType.INLINED));

Expand Down Expand Up @@ -248,7 +248,7 @@ public Optional<RatingSpec> retrieveRatingSpec(String office, String specId) {
.on(specView.RATING_SPEC_CODE.eq(ratView.RATING_SPEC_CODE))
.where(condition)
.orderBy(specView.OFFICE_ID, specView.RATING_ID, ratView.EFFECTIVE_DATE)
.fetchSize(1000);
.fetchSize(DEFAULT_FETCH_SIZE);

logger.fine(() -> query.getSQL(ParamType.INLINED));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public Set<RatingTemplate> retrieveRatingTemplates(String office, String templat
.leftOuterJoin(specView)
.on(specView.TEMPLATE_CODE.eq(tempView.TEMPLATE_CODE))
.where(condition)
.fetchSize(1000);
.fetchSize(DEFAULT_FETCH_SIZE);

logger.fine(() -> query.getSQL(ParamType.INLINED));

Expand Down Expand Up @@ -130,7 +130,7 @@ public Optional<RatingTemplate> retrieveRatingTemplate(String office, String tem
.leftOuterJoin(specView).on(
specView.TEMPLATE_CODE.eq(tempView.TEMPLATE_CODE))
.where(condition)
.fetchSize(1000);
.fetchSize(DEFAULT_FETCH_SIZE);

logger.fine(() -> query.getSQL(ParamType.INLINED));

Expand Down

0 comments on commit dc4e4fe

Please sign in to comment.