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

(fix): Improved immutable state for variable and parallel execution for jsonFilesText. #704

Closed

Conversation

vishal2612200
Copy link

Fix List

  • Parallelize asyncronous file text reading in utils/batch.ts -> getAcceptedFiles
  • Removed mutable variables
  • Improved higher order functions
  • missing (=) in .env.example

@vercel
Copy link

vercel bot commented Dec 3, 2022

@vishal2612200 is attempting to deploy a commit to the thirdweb Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Member

@jnsdls jnsdls left a comment

Choose a reason for hiding this comment

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

hey @vishal2612200 thanks for the PR!

I've left some comments for further improvements that I think we could make on this based on your changes.

In general I believe the promise all approach to parallelizing the json file reading is a good perf win, the pipeFunctionExecutor function (while logical for this use-case) makes the code harder to reason about that it was before and I would like to avoid that.

utils/batch.ts Show resolved Hide resolved
Comment on lines +100 to +104
export const removeEmptyKeysFromObject = (obj: any) =>
Object.keys(obj).reduce((result, key) => {
if (!obj(key) || obj(key).length === 0) return result;
return { ...result, [key]: obj[key] };
}, {} as any);
Copy link
Member

Choose a reason for hiding this comment

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

we started out with any here so not necessary but with this change I believe we can improve the types of this quite a bit by using a generic input type that we remove keys from for the return type based on the same rules as during runtime, something along the lines of:

input: TInputObject extends object
output: Exclude<TInputObject, [keys that are nullish | that are array and have length of 0]>

Comment on lines +114 to +117
return pipeFunctionExecutor(
constructAttributesFromObj,
removeEmptyValues,
)(obj);
Copy link
Member

Choose a reason for hiding this comment

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

I conceptually like it but I have a problem with how much harder it makes this to read / understand what's going on at a glance, I'd prefer to keep the nested functions for this a la convertToOsStandard(removeEmptyKeysFromObject(properties))

Comment on lines +14 to +17
export const pipeFunctionExecutor =
(...fns: any) =>
(...value: any) =>
fns.reduce((result: any, fn: any) => fn(result), ...value);
Copy link
Member

Choose a reason for hiding this comment

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

if we end up going wit this this definitely needs better types than any so it's easier to understand the data flow of this and reason about it when using it

Copy link
Author

Choose a reason for hiding this comment

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

agree with you, we will need better type than any, I was not sure about type over here, so decided to use any over here.

.env.example Outdated Show resolved Hide resolved
@vishal2612200
Copy link
Author

Thanks @jnsdls for comments, I will add your suggested changes in next commit.

@jnsdls jnsdls closed this Jan 26, 2023
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.

None yet

2 participants