improve filename_from_url() performance
Manually extracting the part between the last '/' and '?' instead of relying on the standard libraries' 'urllib.parse.urlsplit()' increases performance by ~400%. urlsplit() : 3.64 secs per 1.000.000 iterations partition(): 0.87 secs per 1.000.000 iterations
This commit is contained in:
parent
968d3e8465
commit
a09f42f6b3
@ -70,7 +70,7 @@ def ensure_http_scheme(url, scheme="https://"):
|
||||
def filename_from_url(url):
|
||||
"""Extract the last part of an URL to use as a filename"""
|
||||
try:
|
||||
return urllib.parse.urlsplit(url).path.rpartition("/")[2]
|
||||
return url.partition("?")[0].rpartition("/")[2]
|
||||
except (TypeError, AttributeError):
|
||||
return ""
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user