mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Removing directory size because it is too slow.
This commit is contained in:
parent
d34dbe7229
commit
47b9d6618c
3 changed files with 1 additions and 39 deletions
|
|
@ -61,14 +61,11 @@ function Folder({folder, onFolderClick, sortData, selectedPaths, onFileClick, on
|
|||
<TableCell collapsing>
|
||||
<Checkbox checked={selectedPaths.indexOf(folder['path']) >= 0} onChange={() => onSelect(folder['path'])}/>
|
||||
</TableCell>
|
||||
<TableCell onClick={() => onFolderClick(path)} className='file-path' disabled={is_empty}>
|
||||
<TableCell onClick={() => onFolderClick(path)} className='file-path' colSpan={2} disabled={is_empty}>
|
||||
{depthIndentation(pathWithNoTrailingSlash)}
|
||||
{is_empty ? <Icon name='folder outline'/> : <Icon name='folder'/>}
|
||||
{name}
|
||||
</TableCell>
|
||||
<TableCell collapsing textAlign='right'>
|
||||
{size > 0 && humanFileSize(size)}
|
||||
</TableCell>
|
||||
</TableRow>;
|
||||
if (children) {
|
||||
// Folder has children, recursively display them.
|
||||
|
|
|
|||
|
|
@ -77,30 +77,14 @@ def get_file_dict(file: str) -> Dict:
|
|||
return _get_file_dict(media_directory / file)
|
||||
|
||||
|
||||
def get_directory_size(directory: pathlib.Path) -> int:
|
||||
"""Returns the size of all the files in the specified directory in bytes using the `du` command."""
|
||||
# Execute the 'du' command to get the total size of the directory
|
||||
result = subprocess.run(['du', '-sb', directory], capture_output=True, check=True, text=True)
|
||||
# The output is in the format "size\t directory\n", so split by tab and take the first element
|
||||
size = int(result.stdout.split("\t")[0])
|
||||
return size - 4096 # Remove size of directory.
|
||||
|
||||
|
||||
@cachetools.func.ttl_cache(10_000, 30.0)
|
||||
def _get_directory_dict(directory: pathlib.Path,
|
||||
directories_cache: str, # Used to cache by requested directories.
|
||||
) -> Dict:
|
||||
media_directory = get_media_directory()
|
||||
try:
|
||||
directory_size = get_directory_size(directory)
|
||||
except Exception as e:
|
||||
logger.error('Failed to get directory size', e)
|
||||
directory_size = 0
|
||||
|
||||
return dict(
|
||||
path=f'{directory.relative_to(media_directory)}/',
|
||||
is_empty=not next(directory.iterdir(), False),
|
||||
size=directory_size,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -587,22 +587,3 @@ async def test_delete_directory_recursive(test_session, test_directory, make_fil
|
|||
empty = test_session.query(FileGroup).one()
|
||||
assert empty.primary_path.name == 'empty'
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_directory_size(test_session, test_directory, make_files_structure, test_async_client):
|
||||
make_files_structure({
|
||||
'foo/one': 'one contents',
|
||||
'foo/two': 'two contents',
|
||||
'bar/one': 'baz contents',
|
||||
})
|
||||
# Make empty directory.
|
||||
(test_directory / 'baz').mkdir()
|
||||
|
||||
request, response = await test_async_client.post('/api/files/refresh')
|
||||
assert response.status_code == HTTPStatus.NO_CONTENT
|
||||
|
||||
request, response = await test_async_client.post('/api/files', content=json.dumps({'directories': []}))
|
||||
assert response.status_code == HTTPStatus.OK
|
||||
assert response.json['files']['foo/']['size'] == 24
|
||||
assert response.json['files']['bar/']['size'] == 12
|
||||
assert response.json['files']['baz/']['size'] == 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue