mirror of
https://github.com/searxng/searxng.git
synced 2025-07-12 07:49:22 +02:00
[perf] torrents.html, files.html: don't parse and re-format filesize
This commit is contained in:
parent
16ce5612dd
commit
e9f8412a6e
13 changed files with 23 additions and 86 deletions
|
@ -332,29 +332,6 @@ def dict_subset(dictionary: MutableMapping, properties: Set[str]) -> Dict:
|
|||
return {k: dictionary[k] for k in properties if k in dictionary}
|
||||
|
||||
|
||||
def get_torrent_size(filesize: str, filesize_multiplier: str) -> Optional[int]:
|
||||
"""
|
||||
|
||||
Args:
|
||||
* filesize (str): size
|
||||
* filesize_multiplier (str): TB, GB, .... TiB, GiB...
|
||||
|
||||
Returns:
|
||||
* int: number of bytes
|
||||
|
||||
Example:
|
||||
>>> get_torrent_size('5', 'GB')
|
||||
5368709120
|
||||
>>> get_torrent_size('3.14', 'MiB')
|
||||
3140000
|
||||
"""
|
||||
try:
|
||||
multiplier = _STORAGE_UNIT_VALUE.get(filesize_multiplier, 1)
|
||||
return int(float(filesize) * multiplier)
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
|
||||
def humanize_bytes(size, precision=2):
|
||||
"""Determine the *human readable* value of bytes on 1024 base (1KB=1024B)."""
|
||||
s = ['B ', 'KB', 'MB', 'GB', 'TB']
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue