Adds performance improvements for volunteer_benefits closing #46

* Major changes, will test more, but appears to be working very well.
This commit is contained in:
Jonathan Rosenbaum
2017-12-16 09:15:50 +00:00
parent 33c5e60969
commit d0028b5779
5 changed files with 168 additions and 122 deletions
+20 -16
View File
@@ -122,7 +122,7 @@ $membership_discount = MEMBERSHIP_DISCOUNT;
LEFT JOIN shop_user_roles ON shop_hours.shop_user_role = shop_user_roles.shop_user_role_id
WHERE (SUBSTRING_INDEX(time_in, ' ', 1) >= DATE_SUB(CURDATE(),INTERVAL 365 DAY)
AND SUBSTRING_INDEX(time_in, ' ', 1) <= DATE_SUB(CURDATE(), INTERVAL 0 DAY))
AND shop_user_roles.volunteer = 1 AND contacts.contact_id=" .
AND shop_user_roles.volunteer = 1 AND " .
$_POST['contact_id'] .
" GROUP BY contact_id) AS firstset
INNER JOIN
@@ -135,28 +135,32 @@ $membership_discount = MEMBERSHIP_DISCOUNT;
WHERE (SUBSTRING_INDEX(time_in, ' ', 1) >= CONCAT(YEAR(CURDATE()),'-01-01')
AND SUBSTRING_INDEX(time_in, ' ', 1) <= DATE_ADD(CONCAT(YEAR(CURDATE()),'-01-01'),INTERVAL DAYOFYEAR(CONCAT(YEAR(CURDATE()),'-12-31')) - 1 DAY))
AND shop_user_roles.volunteer = 1
AND contacts.contact_id=" .
AND " .
$_POST['contact_id'] .
") AS secondset;";
$sql = mysql_query($query, $YBDB) or die(mysql_error());
$result = mysql_fetch_assoc($sql);
$sql = mysql_query($query, $YBDB) or die(mysql_error());
// update volunteer_benefits either on sold_to.change (initialize) or redeem.change in separate callback
// zero out if new year
$result3["max_bike_earned"] = $max_bike_earned;
$result3["volunteer_hour_value"] = $volunteer_hour_value;
$result3["sweat_equity_limit"] = $sweat_equity_limit;
$result3["volunteer_discount"] = $volunteer_discount;
$result3["special_volunteer_hours_qualification"] = $special_volunteer_hours_qualification;
$result3["special_volunteer_discount"] = $special_volunteer_discount;
$result3["stand_time_value"] = $stand_time_value;
$result3["redeem_one_to_one"] = $redeem_one_to_one;
$result = (object)array_merge((array)$result,(array)$result3);
echo json_encode($result);
$volunteers = [];
while ( $result = mysql_fetch_assoc($sql) ) {
$result["max_bike_earned"] = $max_bike_earned;
$result["volunteer_hour_value"] = $volunteer_hour_value;
$result["sweat_equity_limit"] = $sweat_equity_limit;
$result["volunteer_discount"] = $volunteer_discount;
$result["special_volunteer_hours_qualification"] = $special_volunteer_hours_qualification;
$result["special_volunteer_discount"] = $special_volunteer_discount;
$result["stand_time_value"] = $stand_time_value;
$result["redeem_one_to_one"] = $redeem_one_to_one;
$volunteers[] = $result;
}
//return $volunteers;
//$result = (object)array_merge((array)$result,(array)$result3);
echo json_encode($volunteers);
} // end Volunteer Benefits