Skip to content

Commit f2bad50

Browse files
authored
Merge pull request #2632 from internetee/improve-statistics
Improved stats query
2 parents 8cef623 + 31fac9e commit f2bad50

File tree

3 files changed

+3
-20
lines changed

3 files changed

+3
-20
lines changed

app/controllers/repp/v1/stats_controller.rb

+1-16
Original file line numberDiff line numberDiff line change
@@ -139,21 +139,6 @@ def domains_by_registrar(date_to)
139139
140140
UNION ALL
141141
142-
-- Query for 'destroy' events and count the number of domains destroyed associated with each registrar
143-
SELECT
144-
(object_changes->'registrar_id'->>0)::text AS registrar_id,
145-
COUNT(*) AS domain_count
146-
FROM
147-
log_domains
148-
WHERE
149-
event = 'destroy'
150-
AND object_changes->'registrar_id' IS NOT NULL
151-
AND created_at > :date_to
152-
GROUP BY
153-
registrar_id
154-
155-
UNION ALL
156-
157142
-- Query for 'destroy' events and count the number of domains destroyed associated with each registrar
158143
SELECT
159144
(object->'registrar_id')::text AS registrar_id,
@@ -162,7 +147,7 @@ def domains_by_registrar(date_to)
162147
log_domains
163148
WHERE
164149
event = 'destroy'
165-
AND object_changes IS NULL
150+
AND object IS NOT NULL
166151
AND created_at > :date_to
167152
GROUP BY
168153
registrar_id

test/fixtures/files/domain_versions.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Name,Registrant,Registrar,Action,Created at
2-
,John,,destroy,2023-12-04 22:00:00
2+
,John,Good Names,destroy,2023-12-04 22:00:00
33
hospital.test,John,Good Names,create,2023-12-04 22:00:00
44
library.test,Acme Ltd,Best Names,create,2023-12-04 22:00:00
55
shop.test,John,Best Names,update,2023-12-04 22:00:00

test/fixtures/log_domains.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ destroy_one:
7474
event: destroy
7575
object:
7676
registrant_id: <%= ActiveRecord::FixtureSet.identify(:john) %>
77-
object_changes:
78-
name: ['cinema.test', null]
79-
registrar_id: [<%= ActiveRecord::FixtureSet.identify(:goodnames) %>, null]
77+
registrar_id: <%= ActiveRecord::FixtureSet.identify(:goodnames) %>
8078
created_at: <%= Time.zone.parse('2023-12-05') %>
8179

8280
create_six:

0 commit comments

Comments
 (0)