mirror of
https://github.com/HangarMC/Hangar.git
synced 2025-03-13 15:39:18 +08:00
fix(backend): maybe fix stats?
two bugs, views where set to version/project id, not the actual new and old views, plus old views where deleted instantly
This commit is contained in:
parent
e010689954
commit
08ca982834
@ -23,28 +23,30 @@ public interface HangarStatsDAO {
|
||||
void fillStatsUserIdsFromOthers(@Define String table);
|
||||
|
||||
@UseStringTemplateEngine
|
||||
@SqlUpdate("WITH d AS (" +
|
||||
" UPDATE <individualTable> SET processed = processed + 1 " +
|
||||
" WHERE user_id IS <if(withUserId)>NOT<endif> NULL" +
|
||||
" RETURNING created_at, project_id, <if(includeVersionId)>version_id,<endif> <if(withUserId)>user_id<else>address<endif>, processed" +
|
||||
" )" +
|
||||
" INSERT " +
|
||||
" INTO <dayTable> AS pvd (day, project_id, <if(includeVersionId)>version_id,<endif> <statColumn>)" +
|
||||
" SELECT sq.day," +
|
||||
" sq.project_id," +
|
||||
" <if(includeVersionId)>sq.version_id,<endif>" +
|
||||
" count(DISTINCT sq.<if(withUserId)>user_id<else>address<endif>) FILTER (WHERE sq.processed \\<@ ARRAY[1])" +
|
||||
" FROM (SELECT date_trunc('DAY', d.created_at)::date AS day," +
|
||||
" d.project_id," +
|
||||
" <if(includeVersionId)>d.version_id,<endif>" +
|
||||
" <if(withUserId)>user_id<else>address<endif>," +
|
||||
" array_agg(d.processed) AS processed" +
|
||||
" FROM d" +
|
||||
" GROUP BY date_trunc('DAY', d.created_at), d.project_id, <if(includeVersionId)>d.version_id,<endif> <if(withUserId)>user_id<else>address<endif>) sq" +
|
||||
" GROUP BY sq.day, <if(includeVersionId)>sq.version_id,<endif> sq.project_id" +
|
||||
" ON CONFLICT(day, <if(includeVersionId)>version_id<else>project_id<endif>) DO UPDATE SET <statColumn> = pvd.<if(includeVersionId)>version_id<else>project_id<endif> + excluded.<if(includeVersionId)>version_id<else>project_id<endif>")
|
||||
@SqlUpdate("""
|
||||
WITH d AS (
|
||||
UPDATE <individualTable> SET processed = processed + 1
|
||||
WHERE user_id IS <if(withUserId)>NOT<endif> NULL
|
||||
RETURNING created_at, project_id, <if(includeVersionId)>version_id,<endif> <if(withUserId)>user_id<else>address<endif>, processed
|
||||
)
|
||||
INSERT
|
||||
INTO <dayTable> AS pvd (day, project_id, <if(includeVersionId)>version_id,<endif> <statColumn>)
|
||||
SELECT sq.day,
|
||||
sq.project_id,
|
||||
<if(includeVersionId)>sq.version_id,<endif>
|
||||
count(DISTINCT sq.<if(withUserId)>user_id<else>address<endif>) FILTER (WHERE sq.processed \\<@ ARRAY[1])
|
||||
FROM (SELECT date_trunc('DAY', d.created_at)::date AS day,
|
||||
d.project_id,
|
||||
<if(includeVersionId)>d.version_id,<endif>
|
||||
<if(withUserId)>user_id<else>address<endif>,
|
||||
array_agg(d.processed) AS processed
|
||||
FROM d
|
||||
GROUP BY date_trunc('DAY', d.created_at), d.project_id, <if(includeVersionId)>d.version_id,<endif> <if(withUserId)>user_id<else>address<endif>) sq
|
||||
GROUP BY sq.day, <if(includeVersionId)>sq.version_id,<endif> sq.project_id
|
||||
ON CONFLICT(day, <if(includeVersionId)>version_id<else>project_id<endif>) DO UPDATE SET <statColumn> = pvd.<statColumn> + excluded.<statColumn>
|
||||
""")
|
||||
void processStatsMain(@Define String individualTable, @Define String dayTable, @Define String statColumn, @Define boolean withUserId, @Define boolean includeVersionId);
|
||||
|
||||
@SqlUpdate("DELETE FROM <table> WHERE processed != 0 AND created_at < now() + '30 days'::INTERVAL")
|
||||
@SqlUpdate("DELETE FROM <table> WHERE processed != 0 AND created_at < now() - '10 days'::INTERVAL")
|
||||
void deleteOldIndividual(@Define String table);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user