forked from Aspen-Discovery/aspen-discovery
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Aspen-Discovery#2213 from LeoStoyanovByWater/DIS-2…
…50-usage-tables-aggregating-data DIS 250: Fixed Usage Tables Not Aggregating Data Properly
- Loading branch information
Showing
4 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
function getUpdates25_01_02(): array { | ||
$curTime = time(); | ||
return [ | ||
/*'name' => [ | ||
'title' => '', | ||
'description' => '', | ||
'continueOnError' => false, | ||
'sql' => [ | ||
'' | ||
] | ||
], //name*/ | ||
|
||
// Leo Stoyanov - BWS | ||
'aggregate_usage_by_user_agent' => [ | ||
'title' => 'Aggregate usage_by_user_agent & add unique key', | ||
'description' => 'Combine multiple rows per (userAgentId, year, month, instance) into one row before adding unique key', | ||
'continueOnError' => true, | ||
'sql' => [ | ||
// 1) Create a temporary table with the same structure. | ||
"CREATE TABLE usage_by_user_agent_temp LIKE usage_by_user_agent", | ||
|
||
// 2) Insert aggregated data into temp table. | ||
"INSERT INTO usage_by_user_agent_temp (userAgentId, year, month, instance, numRequests, numBlockedRequests) | ||
SELECT userAgentId, year, month, instance, | ||
SUM(numRequests) AS totalRequests, | ||
SUM(numBlockedRequests) AS totalBlocked | ||
FROM usage_by_user_agent | ||
GROUP BY userAgentId, year, month, instance", | ||
|
||
// 3) Clear out original table. | ||
"TRUNCATE TABLE usage_by_user_agent", | ||
|
||
// 4) Re-insert aggregated rows into original table. | ||
"INSERT INTO usage_by_user_agent | ||
SELECT * FROM usage_by_user_agent_temp", | ||
|
||
// 5) Drop the temp table. | ||
"DROP TABLE usage_by_user_agent_temp", | ||
|
||
// 6) Finally, drop the old index and add the unique index. | ||
"ALTER TABLE usage_by_user_agent | ||
DROP INDEX userAgentId, | ||
ADD UNIQUE KEY userAgentId (userAgentId, year, month, instance)" | ||
], | ||
], //aggregate_usage_by_user_agent | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters