From dc4e4fef72fe1713a0e978d280d2c3e77c36080e Mon Sep 17 00:00:00 2001 From: zack-rma Date: Tue, 17 Dec 2024 10:46:31 -0800 Subject: [PATCH] Added global fetchSize variables to DAOs (#877) Added global fetchSize variables to JooqDao and appropriate DAOs --- cwms-data-api/src/main/java/cwms/cda/data/dao/JooqDao.java | 2 ++ .../src/main/java/cwms/cda/data/dao/LocationGroupDao.java | 4 ++-- .../src/main/java/cwms/cda/data/dao/LocationsDaoImpl.java | 6 +++--- .../src/main/java/cwms/cda/data/dao/RatingSpecDao.java | 4 ++-- .../src/main/java/cwms/cda/data/dao/RatingTemplateDao.java | 4 ++-- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dao/JooqDao.java b/cwms-data-api/src/main/java/cwms/cda/data/dao/JooqDao.java index f5a316381..8a702c731 100644 --- a/cwms-data-api/src/main/java/cwms/cda/data/dao/JooqDao.java +++ b/cwms-data-api/src/main/java/cwms/cda/data/dao/JooqDao.java @@ -72,6 +72,8 @@ public abstract class JooqDao extends Dao { 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( diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dao/LocationGroupDao.java b/cwms-data-api/src/main/java/cwms/cda/data/dao/LocationGroupDao.java index 178f3c8e6..33ed666b5 100644 --- a/cwms-data-api/src/main/java/cwms/cda/data/dao/LocationGroupDao.java +++ b/cwms-data-api/src/main/java/cwms/cda/data/dao/LocationGroupDao.java @@ -124,7 +124,7 @@ public Optional 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 = @@ -379,7 +379,7 @@ public List getLocationGroups(String locationOfficeId, String gro Map> 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 list = map.computeIfAbsent(locationGroup, k -> new ArrayList<>()); diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dao/LocationsDaoImpl.java b/cwms-data-api/src/main/java/cwms/cda/data/dao/LocationsDaoImpl.java index 72a2256c8..1d34edbb6 100644 --- a/cwms-data-api/src/main/java/cwms/cda/data/dao/LocationsDaoImpl.java +++ b/cwms-data-api/src/main/java/cwms/cda/data/dao/LocationsDaoImpl.java @@ -121,7 +121,7 @@ public List 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); } @@ -291,7 +291,7 @@ public FeatureCollection buildFeatureCollection(String names, String units, Stri selectQuery = selectQuery.and(AV_LOC.LOCATION_ID.in(identifiers)); } - List features = selectQuery.fetchSize(500).stream() + List features = selectQuery.fetchSize(DEFAULT_SMALL_FETCH_SIZE).stream() .map(LocationsDaoImpl::buildFeatureFromAvLocRecord) .collect(toList()); FeatureCollection collection = new FeatureCollection(); @@ -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 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)) diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dao/RatingSpecDao.java b/cwms-data-api/src/main/java/cwms/cda/data/dao/RatingSpecDao.java index 9ea769ae6..ef251e114 100644 --- a/cwms-data-api/src/main/java/cwms/cda/data/dao/RatingSpecDao.java +++ b/cwms-data-api/src/main/java/cwms/cda/data/dao/RatingSpecDao.java @@ -94,7 +94,7 @@ public Collection 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)); @@ -248,7 +248,7 @@ public Optional 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)); diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dao/RatingTemplateDao.java b/cwms-data-api/src/main/java/cwms/cda/data/dao/RatingTemplateDao.java index a7b60afc6..ee0f1968b 100644 --- a/cwms-data-api/src/main/java/cwms/cda/data/dao/RatingTemplateDao.java +++ b/cwms-data-api/src/main/java/cwms/cda/data/dao/RatingTemplateDao.java @@ -87,7 +87,7 @@ public Set 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)); @@ -130,7 +130,7 @@ public Optional 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));