cds-snc / notification-planning

Project planning for GC Notify Team
4 stars 0 forks source link

API Key Time out #1494

Closed jzbahrai closed 4 months ago

jzbahrai commented 5 months ago

Description

Previously we built this: https://app.zenhub.com/workspaces/notify-planning-614b3ad91bc2030015ed22f5/issues/gh/cds-snc/notification-planning/1413 to try and improve the performance of the API key page. This was unfortunately not good enough as:

  1. It still falls back to notification history if last_used_timestamp is None in the api_keys table
  2. The function for last_used_timestamp doesn't account for "None" if the key has never been used.

Proposal Options:

  1. Make an async celery job that will update the api keys the minute a user logs in. This will give us enough time to populate the last_used_timestamp if it is empty
  2. Write a query that finds all the last_used_timestamp for each key - run this offine in a transaction in hasura - and it will update the api_keys_table

Personally I think we should do (2) as it solves for the None timestamp issue

Once the above is done, change this function: https://github.com/cds-snc/notification-api/blob/main/app/dao/fact_notification_status_dao.py#L359-L372 to not use the notification and notification_history table.

QA Steps

jimleroyer commented 5 months ago

The #2 suggestion does seems like the easiest and more bullet proof considering it would be best to populate all missing records and this is a one time operation.

jzbahrai commented 5 months ago

Completed option 2