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

ref(search): normalize parsed values #69198

Merged
merged 3 commits into from
Apr 18, 2024
Merged

ref(search): normalize parsed values #69198

merged 3 commits into from
Apr 18, 2024

Conversation

JonasBa
Copy link
Member

@JonasBa JonasBa commented Apr 18, 2024

Normalize parsed values. Durations to ms, sizes to bytes, numbers to spoiler alert (numbers), dates to dates and bools to "duh" bools

@github-actions github-actions bot added Scope: Frontend Automatically applied to PRs that change frontend components Scope: Backend Automatically applied to PRs that change backend components labels Apr 18, 2024
Copy link
Contributor

🚨 Warning: This pull request contains Frontend and Backend changes!

It's discouraged to make changes to Sentry's Frontend and Backend in a single pull request. The Frontend and Backend are not atomically deployed. If the changes are interdependent of each other, they must be separated into two pull requests and be made forward or backwards compatible, such that the Backend or Frontend can be safely deployed independently.

Have questions? Please ask in the #discuss-dev-infra channel.

Comment on lines +1044 to +1091
case 'kb':
number *= 1000;
break;
case 'mb':
number *= 1000 ** 2;
break;
case 'gb':
number *= 1000 ** 3;
break;
case 'tb':
number *= 1000 ** 4;
break;
case 'pb':
number *= 1000 ** 5;
break;
case 'eb':
number *= 1000 ** 6;
break;
case 'zb':
number *= 1000 ** 7;
break;
case 'yb':
number *= 1000 ** 8;
break;
case 'kib':
number *= 1024;
break;
case 'mib':
number *= 1024 ** 2;
break;
case 'gib':
number *= 1024 ** 3;
break;
case 'tib':
number *= 1024 ** 4;
break;
case 'pib':
number *= 1024 ** 5;
break;
case 'eib':
number *= 1024 ** 6;
break;
case 'zib':
number *= 1024 ** 7;
break;
case 'yib':
number *= 1024 ** 8;
break;
Copy link
Member

Choose a reason for hiding this comment

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

more of a nit, but you could pretty easily write this with a lookup table no?

const factor = {
  kb: 1000,
  mb: 1000 ** 2,
  ...
  kib: 1024,
  mib: 1024 ** 2,
  ...
} 

number *= factor[unit.toLowerCase()]

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I know. I copied as the exact same code from the backend so that the flow is the same. We could update it on both ends tbh

Comment on lines 1008 to 1027
unit:
| 'bit'
| 'nb'
| 'bytes'
| 'kb'
| 'mb'
| 'gb'
| 'tb'
| 'pb'
| 'eb'
| 'zb'
| 'yb'
| 'kib'
| 'mib'
| 'gib'
| 'tib'
| 'pib'
| 'eib'
| 'zib'
| 'yib'
Copy link
Member

Choose a reason for hiding this comment

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

Are we using this type in multiple places? should it be pulled up?

Copy link
Member Author

Choose a reason for hiding this comment

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

its just in two places. Tbh the better way to type here might be "string" and then just make sure we handle it

Copy link
Member

Choose a reason for hiding this comment

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

sgtm

Copy link

codecov bot commented Apr 18, 2024

Bundle Report

Changes will increase total bundle size by 69.27kB ⬆️

Bundle name Size Change
app-webpack-bundle-array-push 26.24MB 69.27kB ⬆️

@JonasBa JonasBa enabled auto-merge (squash) April 18, 2024 15:55
@JonasBa JonasBa merged commit c418650 into master Apr 18, 2024
50 of 51 checks passed
@JonasBa JonasBa deleted the jb/search/normalizing branch April 18, 2024 16:07
@github-actions github-actions bot locked and limited conversation to collaborators May 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Backend Automatically applied to PRs that change backend components Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants