Uh oh!
There was an error while loading. Please reload this page.
feat: cache IANA TLDs for faster lookups - #390
Conversation
Hi, validators already uses an environment variable to decide whether or not to throw errors, so I thought (again that) we could do something like this instead: class_TLDList:
"""Cache IANA TLDs."""cache=set[str]()
def_load_tld_to_memory(tld_file_path: Path):
"""Load IANA TLDs to memory."""ifnot_TLDList.cache:
withtld_file_path.open() astld_f:
_=next(tld_f) # ignore the first line_TLDList.cache=set(line.strip() forlineintld_f)
return_TLDList.cachedef_iana_tld():
"""Provide IANA TLDs."""# # source: https://data.iana.org/TLD/tlds-alpha-by-domain.txttld_file_path=Path(__file__).parent.joinpath("_tld.txt")
ifenviron.get("LOAD_TLD_TO_MEMORY", "False") =="True":
return_load_tld_to_memory(tld_file_path)
withtld_file_path.open() astld_f:
_=next(tld_f) # ignore the first lineforlineintld_f:
yieldline.strip()Environment |
salty-horse
commented
Jul 17, 2024
Some questions:
|
nandgator
commented
Jul 17, 2024
|
salty-horse
commented
Jul 17, 2024
BTW, I wonder if it's worth it to hardcode |
salty-horse
commented
Jul 17, 2024
Pushed a commit with changes, including my hard-coded list to cover the common TLDs before trying the file. For the documentation, I think it should be covered/linked the domain, hostname, and URL pages, regardless of any other place you think is important. Someone who's just reading about |
nandgator
left a comment
There was a problem hiding this comment.
Feel, free to counter suggest/correct/modify/improve.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
salty-horse
commented
Jul 19, 2024
Should I squash all the commits, or do you want to merge it yourself? |
nandgator
commented
Jul 19, 2024
I'll squash and merge. |
nandgator
commented
Jul 19, 2024
Thanks for the PR! |
salty-horse
commented
Jul 19, 2024
Thank you for the help and accepting the feature! |
Follow-up to the discussion in #362.
I wasn't sure what was meant by using
dataclass, as this isn't a data-first class. I used a regular class, instead.One thing that's obviously missing is tests. I'm not familiar with pytest, and don't know how to re-run the existing domain tests after running the new "load" function.
Here are some basic timing results: