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

Cache outside of the CountryInfo object #40

Open
voidus opened this issue Feb 4, 2022 · 5 comments
Open

Cache outside of the CountryInfo object #40

voidus opened this issue Feb 4, 2022 · 5 comments

Comments

@voidus
Copy link
Contributor

voidus commented Feb 4, 2022

Currently, all files are loaded every time a CountryInfo object is created. That's inefficient and should be changed.

Easiest would probably be to move the data loading part to a cached global function

@atifiu
Copy link
Contributor

atifiu commented Jul 16, 2022

Just wanted to understand what you are suggesting. Move data loading part to global cached function called from init and loading all the files regardless of the country being searched or load only the file for which search is being performed?

@PLPeeters
Copy link

I resorted to the following to only load the data once:

class PatchedCountryInfo(CountryInfo):
    _CountryInfo__countries = None

    def __init__(self, country_name=None):
        if self._CountryInfo__countries is None:
            super().__init__(country_name)

            type(self)._CountryInfo__countries = self._CountryInfo__countries

        self._CountryInfo__country_name = country_name.lower() if country_name else ''

        for country_info in self._CountryInfo__countries.values():
            if self._CountryInfo__country_name in map(lambda an: an.lower(), country_info.get('altSpellings', [])):
                self._CountryInfo__country_name = country_info['name'].lower()
                break

I'd do a PR instead of monkey-patching, but this repo seems pretty dead.

@porimol Are you still maintaining this?

@atifiu
Copy link
Contributor

atifiu commented Feb 3, 2023

Let me know if I can be of any help here.

@PLPeeters
Copy link

@atifiu Your status here is a bit unclear: do you have write access to this repo or are you offering to do the PR?

@atifiu
Copy link
Contributor

atifiu commented Feb 3, 2023

I am offering PR. If we want to activated this repo.

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

No branches or pull requests

3 participants