Revert temporary change for sending expiration email for all SSH keys
What does this MR do and why?
- We started sending SSH key expiration notification emails for all expired keys in the MR !62114 (merged). This change is no longer needed and, therefore, changing back to sending notifications only for the keys that are expiring today.
- Also removing the index that is not required anymore. The queries will now use the index
index_keys_on_expires_at_and_id
.
Database
Migration
Up
== 20211027112901 DropIndexKeysOnExpiresAtAndBeforeExpiryNotificationUndelivered: migrating
-- transaction_open?()
-> 0.0000s
-- indexes(:keys)
-> 0.0049s
-- execute("SET statement_timeout TO 0")
-> 0.0005s
-- remove_index(:keys, {:algorithm=>:concurrently, :name=>"index_keys_on_expires_at_and_expiry_notification_undelivered"})
-> 0.0042s
-- execute("RESET statement_timeout")
-> 0.0006s
== 20211027112901 DropIndexKeysOnExpiresAtAndBeforeExpiryNotificationUndelivered: migrated (0.0329s)
Down
== 20211027112901 DropIndexKeysOnExpiresAtAndBeforeExpiryNotificationUndelivered: reverting
-- transaction_open?()
-> 0.0000s
-- index_exists?(:keys, "date(timezone('UTC', expires_at)), expiry_notification_delivered_at", {:where=>"expiry_notification_delivered_at IS NULL", :name=>"index_keys_on_expires_at_and_expiry_notification_undelivered", :algorithm=>:concurrently})
-> 0.0038s
-- execute("SET statement_timeout TO 0")
-> 0.0005s
-- add_index(:keys, "date(timezone('UTC', expires_at)), expiry_notification_delivered_at", {:where=>"expiry_notification_delivered_at IS NULL", :name=>"index_keys_on_expires_at_and_expiry_notification_undelivered", :algorithm=>:concurrently})
-> 0.0026s
-- execute("RESET statement_timeout")
-> 0.0006s
== 20211027112901 DropIndexKeysOnExpiresAtAndBeforeExpiryNotificationUndelivered: reverted (0.0142s)
Query Plan
explain SELECT "keys".* FROM "keys" WHERE (date(expires_at AT TIME ZONE 'UTC') = CURRENT_DATE AND expiry_notification_delivered_at IS NULL) ORDER BY date(expires_at AT TIME ZONE 'UTC') ASC, "keys"."id" ASC
Index Scan using index_keys_on_expires_at_and_id on public.keys (cost=0.43..36717.41 rows=24797 width=638) (actual time=0.025..0.026 rows=0 loops=1)
Index Cond: (date(timezone('UTC'::text, keys.expires_at)) = CURRENT_DATE)
Buffers: shared hit=4
I/O Timings: read=0.000 write=0.000
Time: 0.333 ms
- planning: 0.276 ms
- execution: 0.057 ms
- I/O read: 0.000 ms
- I/O write: 0.000 ms
Shared buffers:
- hits: 4 (~32.00 KiB) from the buffer pool
- reads: 0 from the OS file cache, including disk I/O
- dirtied: 0
- writes: 0
Screenshots or screen recordings
These are strongly recommended to assist reviewers and reduce the time to merge your change.
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #331927 (closed)
Edited by Huzaifa Iftikhar