Skip to content

Commit

Permalink
Limit the number of generated rows in view_top_proxy_files
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinKolarik committed Oct 17, 2024
1 parent 9e3a3b9 commit f8ca15c
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions migrations/shared/routines.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,20 @@ ${periods.map(period => topProxiesForPeriod(period)).join('\n')}
insert into view_top_proxy_files
(period, date, name, filename, hits, bandwidth)
select aPeriod, aDate,
(select name from proxy where id = proxyId) as name,
filename,
sum(hits) as hits,
sum(bandwidth) as bandwidth
from proxy_file
join proxy_file_hits on proxy_file.id = proxy_file_hits.proxyFileId
where date >= aDateFrom and date <= aDateTo
group by proxy_file.id
order by hits desc;
select aPeriod, aDate, name, filename, hits, bandwidth
from (
select (select name from proxy where id = proxyId) as name,
filename,
sum(hits) as hits,
sum(bandwidth) as bandwidth,
row_number() over (partition by proxyId order by hits desc) as hitsRank,
row_number() over (partition by proxyId order by bandwidth desc) as bandwidthRank
from proxy_file
join proxy_file_hits on proxy_file.id = proxy_file_hits.proxyFileId
where date >= aDateFrom and date <= aDateTo
group by proxy_file.id
) t
where hitsRank <= 10000 or bandwidthRank <= 10000;
call logProcedureCallEnd();
commit;
Expand Down

0 comments on commit f8ca15c

Please sign in to comment.