Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: store analytics_logs allow_list_answers from arrays of objects to object #2945

Merged
merged 4 commits into from
Apr 3, 2024

Conversation

Mike-Heneghan
Copy link
Contributor

@Mike-Heneghan Mike-Heneghan commented Mar 28, 2024

What

Why

  • It was found in Metabase / SQL that the allow_list_answers as an array is harder to work with
  • Useful to align the data structure to that of lowcal_sessions
  • Currently, we are occasionally storing null values from some edge case nodes

Follow Up

  • Although the changes in this PR should stop null being stored in allow_list_answers it doesn't cleanup historical data which will be done in a follow up PR.
  • Viewing analytics_logs and analytics_summary on .dev it looks like the data was updated as expected 🥳

- Align the data structure of the `allow_list_answers` to the `submission_services_summary`
- Filter out null answer values from getAnswers
- Return null when no allow_list_answers found
@Mike-Heneghan Mike-Heneghan self-assigned this Mar 28, 2024
- Convert from an array of objects to a single object
- Currently we have no records in prod where the [allow_list_answers is longer than 1](https://metabase.editor.planx.uk/question/354-number-of-analytics-logs-with-allow-list-answers-greater-than-1) so we can use this to convert
- Update the `analytics_summary` db view to handle the change to the data structure
@Mike-Heneghan Mike-Heneghan force-pushed the mh/align-allow-list-answers-data-structure branch from 5d2cec6 to 48cb555 Compare March 28, 2024 17:04
@Mike-Heneghan
Copy link
Contributor Author

- Assumption that only one passport variable was set at a time and that it was defined by the flow was proven wrong
- Therefore node_fn was not accurate and the tracking of it unnecessary as the associated passport key is stored in the allow_list_answers object
Copy link

github-actions bot commented Mar 28, 2024

🤖 Hasura Change Summary compared a subset of table metadata including permissions:

Updated Tables (1)

  • public.analytics_logs permissions:

    insert select update delete
    public /
    1 removed column permissions
    insert select update
    public ➖ node_fn

@Mike-Heneghan Mike-Heneghan marked this pull request as ready for review March 28, 2024 17:15
@Mike-Heneghan Mike-Heneghan requested a review from a team March 28, 2024 17:15
Copy link

github-actions bot commented Mar 28, 2024

Removed vultr server and associated DNS entries

Copy link
Contributor

@DafyddLlyr DafyddLlyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comment on some possible TypeScript tidy ups but looking good!

if (!nodeFn || !ALLOW_LIST.includes(nodeFn)) return [];
const nodeFn: string | undefined = data?.fn || data?.val;

if (!nodeFn || !ALLOW_LIST.includes(nodeFn as AllowListKey)) return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!nodeFn || !ALLOW_LIST.includes(nodeFn as AllowListKey)) return;
const isAllowListKey = (nodeFn: string): nodeFn is AllowListKey => {
return (ALLOW_LIST as readonly string[]).includes(nodeFn);
};
if (!nodeFn || !isAllowListKey(nodeFn)) return;

If we add a type guard here instead of just .includes() we'll get type narrowing and can drop the casting to AllowListKey on line 526.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a much neater solution 🙌

I wasn't happy with the type casting but I couldn't figure out an improvement, I'll keep this pattern in mind going forward 😊

Should be sorted here: 9bccce1

const filteredEntries = Object.entries(dataSetByNode)
.filter(
([key, value]) =>
ALLOW_LIST.includes(key as AllowListKey) && Boolean(value),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comment on using a type guard (is function) - we can probably use one here to avoid casting twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also be sorted by: 9bccce1

@Mike-Heneghan Mike-Heneghan merged commit 97e1330 into main Apr 3, 2024
12 checks passed
@Mike-Heneghan Mike-Heneghan deleted the mh/align-allow-list-answers-data-structure branch April 5, 2024 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants