Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added global fetchSize variables to DAOs #877

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -70,6 +70,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 @@ -123,7 +123,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 @@ -290,7 +290,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
Loading