Skip to content

[HOLD for payment 2024-11-11] [250] Use general-purpose memoization lib in Localize #50194

Closed

Description

@roryabraham

This is essentially a follow-up for https://expensify.slack.com/archives/C01GTK53T8Q/p1716371827915779. Just a bit of cleanup.

Problem

We have built a general-purpose memoziation lib and standardized on using it as a best practice for consistency. However, in src/libs/Localize we still have a different custom memoization/cache implementation.

Solution

Refactor src/libs/Localize to use the general-purpose memoization lib

Issue OwnerCurrent Issue Owner: @abekkala

Activity

  1. added
    ExternalAdded to denote the issue can be worked on by a contributor
    BugSomething is broken. Auto assigns a BugZero manager.
    on Oct 3, 2024
  2. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Oct 3, 2024
  3. melvin-bot commented on Oct 3, 2024

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @hoangzinh (External)

  4. roryabraham commented on Oct 3, 2024

    @roryabraham
    ContributorAuthor
  5. melvin-bot commented on Oct 3, 2024

    @melvin-bot

    Triggered auto assignment to @abekkala (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  6. shijir0927 commented on Oct 4, 2024

    @shijir0927

    Proposal


    Please re-state the problem that we are trying to solve in this issue.

    utils/Localize still uses it's own memoization implementation using translationCache function which is not in alignment with the best practice since all/most? other places are using utils/memoize

    What is the root cause of that problem?

    Just a refactor that was left behind and needs to be done

    What changes do you think we should make in order to solve the problem?

    Since utils/memoize is just wrapping a function with memoization layer and returning the memoized value,

    1. In utils/Localize getTranslatedPhrase() function, we can get rid of the logic that is manually setting and checking the phrase in a map which makes the function translationCache() obselete.
      https://github.com/Expensify/App/blob/821edc51788b616e323cae0dc00f4b0aa7246766/src/libs/Localize/index.ts#L89C1-L99C6

    2. Use the new memoize utility function wrapping the getTranslatedPhrase() value
      https://github.com/Expensify/App/blob/821edc51788b616e323cae0dc00f4b0aa7246766/src/libs/Localize/index.ts#L171C1-L177C103

    I can make the the refactor here if you want to make sure it works and won't create any unwanted behavior. I'll also backfill a unit test in LocalizeTests.ts for checking the memoization actually works unless you think that's extra.

    What alternative solutions did you explore? (Optional)

    Since we already have a utility function that we specifically want to use, no alternative solution is explored.

  7. melvin-bot commented on Oct 4, 2024

    @melvin-bot
  8. shijir0927 commented on Oct 4, 2024

    @shijir0927
  9. melvin-bot commented on Oct 4, 2024

    @melvin-bot
  10. shubham1206agra commented on Oct 4, 2024

    @shubham1206agra
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue

    Use general-purpose memoization lib in Localize

    What is the root cause of that problem?

    Feature Request

    What changes do you think we should make in order to solve the problem?

    We need to cache getTranslatedPhrase using memoize present under @libs/memoize module.

    We will use the following code to create memorized function.

    const memoizedGetTranslatedPhrase = memoize(getTranslatedPhrase, {
        monitoringName: 'getTranslatedPhrase',
        transformKey: ([language, phraseKey, fallbackLanguage, ...parameters]) => `${language}-${phraseKey}-${fallbackLanguage}-${parameters.length > 0 ? JSON.stringify(parameters.at(0)) : ''}`,
    });

    And use it in

    const translatedPhrase = getTranslatedPhrase(language, path, languageAbbreviation, ...parameters);

    And remove the old memoize code present

    const translationCache = new Map<ValueOf<typeof CONST.LOCALES>, Map<TranslationPaths, string>>(

    Test branch. - https://github.com/shubham1206agra/App/tree/test-localize-memoize

    What alternative solutions did you explore? (Optional)

  11. hoangzinh commented on Oct 4, 2024

    @hoangzinh
    Contributor

    @roryabraham just wants to confirm if @kacper-mikolajczak will work on this issue or it's opened for external contributors?

  12. 46 remaining items

  13. changed the title [-][250] Use general-purpose memoization lib in Localize[/-] [+][HOLD for payment 2024-11-11] [250] Use general-purpose memoization lib in Localize[/+] on Nov 4, 2024
  14. melvin-bot commented on Nov 4, 2024

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  15. melvin-bot commented on Nov 4, 2024

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.56-9 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2024-11-11. 🎊

    For reference, here are some details about the assignees on this issue:

  16. melvin-bot commented on Nov 4, 2024

    @melvin-bot

    @hoangzinh / @shubham1206agra @abekkala The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

  17. abekkala commented on Nov 5, 2024

    @abekkala
    Contributor

    PAYMENT SUMMARY FOR NOV 11

  18. hoangzinh commented on Nov 6, 2024

    @hoangzinh
    Contributor

    BugZero Checklist:

    • [Contributor] Classify the bug: It's not a bug issue, it's a refactoring issue
    Bug classification

    Source of bug:

    • 1a. Result of the original design (eg. a case wasn't considered)
    • 1b. Mistake during implementation
    • 1c. Backend bug
    • [x ] 1z. Other:

    Where bug was reported:

    • 2a. Reported on production
    • 2b. Reported on staging (deploy blocker)
    • 2c. Reported on a PR
    • 2z. Other:

    Who reported the bug:

    • 3a. Expensify user
    • 3b. Expensify employee
    • 3c. Contributor
    • 3d. QA
    • 3z. Other:
    • [Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.

      Link to comment: N/A

    • [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.

      Link to discussion: N/A

    • [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.
      No, we don't need a regression test for this issue. It's already covered somewhere

  19. melvin-bot commented on Nov 11, 2024

    @melvin-bot

    Payment Summary

    Upwork Job

    BugZero Checklist (@abekkala)

  20. abekkala commented on Nov 11, 2024

    @abekkala
    Contributor

    @shubham1206agra can you accept the offer in Upwork? I can then process payment today, thanks!

  21. shubham1206agra commented on Nov 11, 2024

    @shubham1206agra
    Contributor
  22. abekkala commented on Nov 11, 2024

    @abekkala
    Contributor

    @shubham1206agra payment sent and contract ended - thank you! 🎉

  23. abekkala commented on Nov 11, 2024

    @abekkala
    Contributor

    PAYMENT SUMMARY FOR NOV 11

  24. garrettmknight commented on Nov 13, 2024

    @garrettmknight
    Contributor

    $250 approved for @hoangzinh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

AutoAssignerNewDotQualityUsed to assign quality issues to engineersAwaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.ExternalAdded to denote the issue can be worked on by a contributorWeeklyKSv2

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions