Fix #8422: Fix False usage query count (#9587)

This commit is contained in:
Mayur Singal 2023-01-04 14:01:07 +05:30 committed by GitHub
parent 1f49ea46b5
commit 67ea711319
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 5 deletions

View File

@ -194,7 +194,7 @@ class OMetaTableMixin:
:param table: Table Entity to update
:param table_usage_request: Usage data to add
"""
resp = self.client.put(
resp = self.client.post(
f"/usage/table/{table.id.__root__}", data=table_usage_request.json()
)
logger.debug("published table usage %s", resp)

View File

@ -2263,16 +2263,19 @@ public interface CollectionDAO {
+ "(:count1 + (SELECT COALESCE(SUM(count1), 0) FROM entity_usage WHERE id = :id AND usageDate >= :date - "
+ "INTERVAL 6 DAY)), "
+ "(:count1 + (SELECT COALESCE(SUM(count1), 0) FROM entity_usage WHERE id = :id AND usageDate >= :date - "
+ "INTERVAL 29 DAY))",
+ "INTERVAL 29 DAY))"
+ "ON DUPLICATE KEY UPDATE count7 = count7 - count1 + :count1, count30 = count30 - count1 + :count1, count1 = :count1",
connectionType = MYSQL)
@ConnectionAwareSqlUpdate(
value =
"INSERT INTO entity_usage (usageDate, id, entityType, count1, count7, count30) "
+ "SELECT (:date :: date), :id, :entityType, :count1, "
+ "(:count1 + (SELECT COALESCE(SUM(count1), 0) FROM entity_usage WHERE id = :id AND usageDate >= (:date :: date) - INTERVAL '6 days')), "
+ "(:count1 + (SELECT COALESCE(SUM(count1), 0) FROM entity_usage WHERE id = :id AND usageDate >= (:date :: date) - INTERVAL '29 days'))",
+ "(:count1 + (SELECT COALESCE(SUM(count1), 0) FROM entity_usage WHERE id = :id AND usageDate >= (:date :: date) - INTERVAL '29 days'))"
+ "ON CONFLICT (usageDate, id) DO UPDATE SET count7 = entity_usage.count7 - entity_usage.count1 + :count1,"
+ "count30 = entity_usage.count30 - entity_usage.count1 + :count1, count1 = :count1",
connectionType = POSTGRES)
void insert(
void insertOrReplaceCount(
@Bind("date") String date,
@Bind("id") String id,
@Bind("entityType") String entityType,

View File

@ -190,7 +190,7 @@ public class UsageRepository {
private void insertToUsageRepository(String method, String entityId, String entityType, DailyCount usage) {
if (method.equals(POST)) {
dao.usageDAO().insert(usage.getDate(), entityId, entityType, usage.getCount());
dao.usageDAO().insertOrReplaceCount(usage.getDate(), entityId, entityType, usage.getCount());
} else if (method.equals(PUT)) {
dao.usageDAO().insertOrUpdateCount(usage.getDate(), entityId, entityType, usage.getCount());
}