Author: bleny Date: 2013-07-04 15:26:41 +0200 (Thu, 04 Jul 2013) New Revision: 286 Url: http://forge.codelutin.com/projects/franciaflex-magalie/repository/revisions... Log: add some elements to heap finding performance issue in article reception Modified: trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/FixturesService.java trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ReceptionService.java trunk/magalie-services/src/test/java/com/franciaflex/magalie/services/service/ReceptionServiceTest.java trunk/magalie-web/src/main/webapp/js/receive-article-input.js Modified: trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/FixturesService.java =================================================================== --- trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/FixturesService.java 2013-07-04 09:06:18 UTC (rev 285) +++ trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/FixturesService.java 2013-07-04 13:26:41 UTC (rev 286) @@ -160,6 +160,24 @@ } +// Warehouse u01 = fixtures.fixture("U01"); +// +// Warehouse u02 = fixtures.fixture("U02"); +// +// for (int i = 1 ; i <= 10000 ; i++) { +// +// Location location = new Location(); +// +// String locationCode = String.valueOf(i); +// +// location.setCode(locationCode); +// +// location.setWarehouse(i % 2 == 0 ? u01 : u02); +// +// locationDao.persist(location); +// +// } + SupplierJpaDao supplierDao = persistenceContext.getSupplierDao(); Collection<Supplier> suppliers = fixtures.fixture("suppliers"); Modified: trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ReceptionService.java =================================================================== --- trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ReceptionService.java 2013-07-04 09:06:18 UTC (rev 285) +++ trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ReceptionService.java 2013-07-04 13:26:41 UTC (rev 286) @@ -219,6 +219,10 @@ protected List<Location> findLocationsToReceiveArticle(Warehouse warehouse, Article article) { + if (log.isTraceEnabled()) { + log.trace("looking for locations to receive for " + article + " in " + warehouse); + } + // first step, add fixed locations for this article first Set<Location> locations = Sets.newLinkedHashSet(); @@ -265,7 +269,8 @@ locations.addAll(locationDao.findAllWithoutReception(warehouse)); // add all locations in the same building, other warehouses - locations.addAll(locationDao.findAllWithoutReception(warehouse.getBuilding())); + // FIXME brendan 04/07/13 re-enable + // locations.addAll(locationDao.findAllWithoutReception(warehouse.getBuilding())); // fourth step, remove reception locations because it's stupid to // move an article from reception location to another reception location @@ -292,7 +297,7 @@ ); if (log.isDebugEnabled()) { - log.debug("locations to receive articles for article " + log.debug(result.size() + "locations to receive articles for article " + article + " in warehouse " + warehouse + " are " + StringUtils.join(result, ", ")); } Modified: trunk/magalie-services/src/test/java/com/franciaflex/magalie/services/service/ReceptionServiceTest.java =================================================================== --- trunk/magalie-services/src/test/java/com/franciaflex/magalie/services/service/ReceptionServiceTest.java 2013-07-04 09:06:18 UTC (rev 285) +++ trunk/magalie-services/src/test/java/com/franciaflex/magalie/services/service/ReceptionServiceTest.java 2013-07-04 13:26:41 UTC (rev 286) @@ -35,6 +35,7 @@ import com.franciaflex.magalie.persistence.entity.StorageMovement; import com.franciaflex.magalie.persistence.entity.StoredArticle; import com.franciaflex.magalie.persistence.entity.Supplier; +import com.franciaflex.magalie.persistence.entity.Warehouse; import com.franciaflex.magalie.services.AbstractMagalieServiceTest; import com.franciaflex.magalie.services.exception.InvalidMagalieBarcodeException; import com.franciaflex.magalie.services.exception.PreparedArticleReceptionAlreadyStoredException; @@ -46,6 +47,8 @@ import org.junit.Before; import org.junit.Test; +import javax.persistence.EntityManager; +import javax.persistence.EntityTransaction; import java.text.ParseException; import java.util.Date; import java.util.List; @@ -310,4 +313,47 @@ } + /** + * It's only a performance test to test with 5000+ locations. + */ + @Test + public void testName() { + + EntityManager entityManager = getJpaEntityManagerRule().newEntityManager(); + + EntityTransaction transaction = entityManager.getTransaction(); + + transaction.begin(); + + Warehouse u01 = fixture("U01"); + + Warehouse u02 = fixture("U02"); + + for (int i = 1 ; i <= 5000 ; i++) { + + Location location = new Location(); + + String locationCode = String.valueOf(i); + + location.setCode(locationCode); + + location.setWarehouse(i % 2 == 0 ? u01 : u02); + + entityManager.persist(location); + + } + + transaction.commit(); + + long time = System.currentTimeMillis(); + + List<Location> locations = service.findLocationsToReceiveArticle(u02, article); + + if (log.isTraceEnabled()) { + log.trace("getting a result of " + locations.size() + + " locations took " + (System.currentTimeMillis() - time)); + } + + } + } Modified: trunk/magalie-web/src/main/webapp/js/receive-article-input.js =================================================================== --- trunk/magalie-web/src/main/webapp/js/receive-article-input.js 2013-07-04 09:06:18 UTC (rev 285) +++ trunk/magalie-web/src/main/webapp/js/receive-article-input.js 2013-07-04 13:26:41 UTC (rev 286) @@ -50,6 +50,9 @@ } } if (location == null) { + // try to load it form JSON request ? + } + if (location == null) { throw new ValidationError(barcode + " n'est pas le code barre d'un emplacement valide"); } return location;