Skip to content

Commit

Permalink
Merge pull request #111 from openboxes/feature/#100-improve-performan…
Browse files Browse the repository at this point in the history
…ce-qoh-job

Feature/#100 improve performance of automated inventory snapshot process
  • Loading branch information
jmiranda committed Oct 4, 2015
2 parents 5bfc3ff + 36c785f commit 3b7754c
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 117 deletions.
1 change: 1 addition & 0 deletions grails-app/conf/UrlMappings.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class UrlMappings {

"/admin/manage/$action?"(controller: "adminManage")
"/adminManage/$action?"(controller: "errors", action: "urlMapping")
"/snapshot/$action?"(controller: "inventorySnapshot")

"/$controller/$action?/$id?" {
constraints {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,35 @@ class CalculateQuantityJob {

// System uses yesterday by default if a date is not provided
if (!date) {
log.info "Date is being set to yesterday"
log.info "Date is being set to midnight tonight"
date = new Date()
date.clearTime()
//date.clearTime()
}

log.info "Executing calculate quantity job for date=${date}, user=${user}, location=${location}, product=${product}, mergedJobDataMap=${context.mergedJobDataMap}"


// Triggered ??
if (product && date && location) {
println "Triggered calculate quantity job for product ${product} at ${location} on ${date}"
inventoryService.createOrUpdateInventorySnapshot(date, location, product)
}
// Triggered by the inventory snapshot tab off the product page
else if (product && location) {
println "Triggered calculate quantity job for product ${product} at ${location} on ${date}"
inventoryService.createOrUpdateInventorySnapshot(location, product)
}
// Triggered by the Inventory Snapshot page
else if (date && location) {
println "Triggered calculate quantity job for all products at ${location} on ${date}"
inventoryService.createOrUpdateInventorySnapshot(date, location)
inventoryService.createOrUpdateInventoryItemSnapshot(date, location)
}
// Triggered by the CalculateQuantityJob
else if (date) {
println "Triggered calculate quantity job for all locations and products on ${date}"
inventoryService.createOrUpdateInventorySnapshot(date)
inventoryService.createOrUpdateInventoryItemSnapshot(date)
}
else if (location) {
println "Triggered calculate quantity job for all products at location ${location} over all dates"
inventoryService.createOrUpdateInventorySnapshot(location)
}
else {
println "Triggered calculate quantity job for all dates, locations, products"
def transactionDates = inventoryService.getTransactionDates()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http:https://www.liquibase.org/xml/ns/dbchangelog/1.9"
xmlns:xsi="http:https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http:https://www.liquibase.org/xml/ns/dbchangelog/1.9 http:https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd">

<changeSet author="jmiranda" id="1442807680525-1">
<addUniqueConstraint constraintName="inventory_snapshot_key"
tableName="inventory_snapshot"
columnNames="date, location_id, product_id"/>
</changeSet>

<changeSet author="jmiranda" id="1442807680525-2">
<addUniqueConstraint constraintName="inventory_item_snapshot_key"
tableName="inventory_item_snapshot"
columnNames="date, location_id, product_id, inventory_item_id"/>
</changeSet>


<!--
<changeSet author="jmiranda" id="1442807680525-3">
<comment>Need to update the ID column for all records so that they are set to an auto-incremented value during modify column operation.</comment>
<sql>
UPDATE inventory_snapshot set id = NULL;
</sql>
<modifyColumn tableName="inventory_snapshot">
<column name="id" type="bigint(20)" autoIncrement="true">
<constraints nullable="false" primaryKey="true" primaryKeyName="inventory_snapshot_pk"/>
</column>
</modifyColumn>
</changeSet>
-->

</databaseChangeLog>
2 changes: 1 addition & 1 deletion grails-app/migrations/0.6.x/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
<include file="0.6.x/modify-column-order-unit-price.xml"/>
<include file="0.6.x/create-table-inventory-item-snapshot.xml"/>
<include file="0.6.x/add-column-user-timezone.xml"/>

<include file="0.6.x/add-unique-index-to-snapshot-tables.xml"/>
</databaseChangeLog>
Loading

0 comments on commit 3b7754c

Please sign in to comment.