App: [hold for payment 2024-04-17] [$500] Improve performance of getPersonalDetailByEmail

Problem

We sometimes have the need to get personal data based on an email, currently the way to do it is calling getPersonalDetailByEmail which will loop over every value in our personalDetails array and check which one matches with the email we want, making this a O(n) search. The problem is that this can be really slow for policies with too many users creating a bad user experience.

Solution

Use the data we have stored in personalDetails and create a cached map keyed by email so we can use that map in getPersonalDetailByEmail making the search O(1). We should also update the cache whenever personalDetails change.

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~014394e09fe6cfc357
  • Upwork Job ID: 1772362853753180160
  • Last Price Increase: 2024-04-01
  • Automatic offers:
    • rojiphil | Reviewer | 0
    • abzokhattab | Contributor | 0

About this issue

  • Original URL
  • State: closed
  • Created 3 months ago
  • Comments: 47 (34 by maintainers)

Most upvoted comments

are we close to selecting a proposal here?

@joekaufmanexpensify Yes. The selection remains the same as mentioned here i.e. @abzokhattab proposal LGTM Awaiting @luacmartins to weigh in.

But still if you want or if you can consider my proposal then I can do some changes in it

@godofoutcasts94 Not in this issue. I just gave you feedback so that you can consider these inputs while you write your next proposal elsewhere.

Thanks all for your proposals. @ahmedGaber93 Your proposal could have advantage of less memory consumption but this would result in O(1)+O(1) time complexity which is less efficient than O(1) @godofoutcasts94 Your proposal focusses on a generic implementation but lacks clarity on how it integrates with the existing code base. e.g. We do not have to define PersonalDetails as the type already exists. @FitseTLT @abzokhattab @nayabatir1 @ikevin127 Your proposals have similar implementations with O(1) time complexity.

@abzokhattab proposal LGTM as that was the first one to have a more complete workable solution than others. As an optimization, we can populate emailToDetailsCache within Onyx.connect callback itself. But, we can take this up at the PR stage.
🎀👀🎀 C+ reviewed