From 0d2ba34d2cd8b7a205c26a7349e233cd88e2f056 Mon Sep 17 00:00:00 2001 From: "pushpraj.jadoun" Date: Wed, 25 Feb 2026 12:57:46 +0530 Subject: [PATCH 1/3] (OFBIZ-13366) : Implemented support to use limit and offset properly to fetch only limited records instead of fetching all the records from the DB --- .../ofbiz/webtools/entity/FindGeneric.groovy | 55 ++++++++++++++----- 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/framework/webtools/src/main/groovy/org/apache/ofbiz/webtools/entity/FindGeneric.groovy b/framework/webtools/src/main/groovy/org/apache/ofbiz/webtools/entity/FindGeneric.groovy index 4d6535a4b8f..455cc6a8586 100644 --- a/framework/webtools/src/main/groovy/org/apache/ofbiz/webtools/entity/FindGeneric.groovy +++ b/framework/webtools/src/main/groovy/org/apache/ofbiz/webtools/entity/FindGeneric.groovy @@ -19,6 +19,8 @@ package org.apache.ofbiz.webtools.entity import org.apache.ofbiz.base.util.UtilXml +import org.apache.ofbiz.entity.util.EntityQuery + import org.apache.ofbiz.entity.GenericEntityException import org.apache.ofbiz.entity.model.ModelEntity import org.apache.ofbiz.entity.model.ModelFieldType @@ -96,25 +98,52 @@ if (modelEntity) { dynamicAutoEntitySearchFormRenderer.render(writer, context) context.dynamicAutoEntitySearchForm = writer - //prepare the result list from performFind + // Prepare the data retrieval using EntityQuery with limit and offset for better performance + int viewIndex = [parameters.VIEW_INDEX_1, parameters.VIEW_INDEX, parameters.viewIndex].find { String val -> val?.isInteger() }?.toInteger() ?: 0 + int viewSize = [parameters.VIEW_SIZE_1, parameters.VIEW_SIZE, parameters.viewSize].find { String val -> val?.isInteger() }?.toInteger() ?: 20 + + Map prepareFindResult = dispatcher.runSync('prepareFind', [ + entityName : entityName, + inputFields : parameters, + orderBy : parameters.sortField, + noConditionFind: parameters.noConditionFind ?: 'Y' + ]) + + if (prepareFindResult.entityConditionList || parameters.noConditionFind == 'Y') { + EntityQuery query = EntityQuery.use(delegator) + .from(entityName) + .limit(viewSize) + .offset(viewIndex * viewSize) + .cursorScrollInsensitive() + + if (prepareFindResult.entityConditionList) { + query.where(prepareFindResult.entityConditionList) + } + + if (prepareFindResult.orderByList) { + query.orderBy(prepareFindResult.orderByList) + } + + if (fieldsToSelect) { + query.select(fieldsToSelect as Set) + } + + if (parameters.distinct == 'Y') { + query.distinct() + } + + context.listIt = query.queryIterator() + context.listSize = context.listIt.getResultsSizeAfterPartialList() + } + + //prepare the result list String dynamicAutoEntityFieldListForm = """
- - - - """ - if (fieldsToSelect) { - dynamicAutoEntityFieldListForm += """ - """ - } - dynamicAutoEntityFieldListForm += """ - - - """ From 673d227d81c72267052f6026131337bd5c37f88c Mon Sep 17 00:00:00 2001 From: "pushpraj.jadoun" Date: Wed, 25 Feb 2026 14:11:04 +0530 Subject: [PATCH 2/3] (OFBIZ-13366) : Removed the extra space and format code properly --- .../org/apache/ofbiz/webtools/entity/FindGeneric.groovy | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/framework/webtools/src/main/groovy/org/apache/ofbiz/webtools/entity/FindGeneric.groovy b/framework/webtools/src/main/groovy/org/apache/ofbiz/webtools/entity/FindGeneric.groovy index 455cc6a8586..0319868e3c5 100644 --- a/framework/webtools/src/main/groovy/org/apache/ofbiz/webtools/entity/FindGeneric.groovy +++ b/framework/webtools/src/main/groovy/org/apache/ofbiz/webtools/entity/FindGeneric.groovy @@ -20,7 +20,6 @@ package org.apache.ofbiz.webtools.entity import org.apache.ofbiz.base.util.UtilXml import org.apache.ofbiz.entity.util.EntityQuery - import org.apache.ofbiz.entity.GenericEntityException import org.apache.ofbiz.entity.model.ModelEntity import org.apache.ofbiz.entity.model.ModelFieldType @@ -103,9 +102,9 @@ if (modelEntity) { int viewSize = [parameters.VIEW_SIZE_1, parameters.VIEW_SIZE, parameters.viewSize].find { String val -> val?.isInteger() }?.toInteger() ?: 20 Map prepareFindResult = dispatcher.runSync('prepareFind', [ - entityName : entityName, - inputFields : parameters, - orderBy : parameters.sortField, + entityName: entityName, + inputFields: parameters, + orderBy: parameters.sortField, noConditionFind: parameters.noConditionFind ?: 'Y' ]) From 2cdb5af3000688851b5646b7f488ad7ecc2f6ff8 Mon Sep 17 00:00:00 2001 From: pushprajsinghjadoun Date: Mon, 2 Mar 2026 14:21:42 +0530 Subject: [PATCH 3/3] (OFBIZ-13366) : Added the default sorting logic for limit and offset --- .../groovy/org/apache/ofbiz/webtools/entity/FindGeneric.groovy | 2 ++ 1 file changed, 2 insertions(+) diff --git a/framework/webtools/src/main/groovy/org/apache/ofbiz/webtools/entity/FindGeneric.groovy b/framework/webtools/src/main/groovy/org/apache/ofbiz/webtools/entity/FindGeneric.groovy index 0319868e3c5..810bf18e11a 100644 --- a/framework/webtools/src/main/groovy/org/apache/ofbiz/webtools/entity/FindGeneric.groovy +++ b/framework/webtools/src/main/groovy/org/apache/ofbiz/webtools/entity/FindGeneric.groovy @@ -121,6 +121,8 @@ if (modelEntity) { if (prepareFindResult.orderByList) { query.orderBy(prepareFindResult.orderByList) + } else { + query.orderBy(modelEntity.getPkFieldNames()) } if (fieldsToSelect) {