Skip to content

Commit

Permalink
Merge pull request #2632 from internetee/improve-statistics
Browse files Browse the repository at this point in the history
Improved stats query
  • Loading branch information
vohmar authored Dec 22, 2023
2 parents 8cef623 + 31fac9e commit f2bad50
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 20 deletions.
17 changes: 1 addition & 16 deletions app/controllers/repp/v1/stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,6 @@ def domains_by_registrar(date_to)
UNION ALL
-- Query for 'destroy' events and count the number of domains destroyed associated with each registrar
SELECT
(object_changes->'registrar_id'->>0)::text AS registrar_id,
COUNT(*) AS domain_count
FROM
log_domains
WHERE
event = 'destroy'
AND object_changes->'registrar_id' IS NOT NULL
AND created_at > :date_to
GROUP BY
registrar_id
UNION ALL
-- Query for 'destroy' events and count the number of domains destroyed associated with each registrar
SELECT
(object->'registrar_id')::text AS registrar_id,
Expand All @@ -162,7 +147,7 @@ def domains_by_registrar(date_to)
log_domains
WHERE
event = 'destroy'
AND object_changes IS NULL
AND object IS NOT NULL
AND created_at > :date_to
GROUP BY
registrar_id
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/files/domain_versions.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name,Registrant,Registrar,Action,Created at
,John,,destroy,2023-12-04 22:00:00
,John,Good Names,destroy,2023-12-04 22:00:00
hospital.test,John,Good Names,create,2023-12-04 22:00:00
library.test,Acme Ltd,Best Names,create,2023-12-04 22:00:00
shop.test,John,Best Names,update,2023-12-04 22:00:00
Expand Down
4 changes: 1 addition & 3 deletions test/fixtures/log_domains.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ destroy_one:
event: destroy
object:
registrant_id: <%= ActiveRecord::FixtureSet.identify(:john) %>
object_changes:
name: ['cinema.test', null]
registrar_id: [<%= ActiveRecord::FixtureSet.identify(:goodnames) %>, null]
registrar_id: <%= ActiveRecord::FixtureSet.identify(:goodnames) %>
created_at: <%= Time.zone.parse('2023-12-05') %>

create_six:
Expand Down

0 comments on commit f2bad50

Please sign in to comment.