Skip to content

Commit

Permalink
cache for file-browsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ansibleguy committed Feb 9, 2024
1 parent 3523812 commit 12dc5bb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/ansible-webui/aw/api_endpoints/filesystem.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from os import listdir
from os import path as os_path
from pathlib import Path
from functools import cache

from rest_framework.views import APIView
from rest_framework import serializers
Expand All @@ -25,6 +26,11 @@ class APIFsBrowse(APIView):
'inventory_file': config['path_play'],
}

@staticmethod
@cache
def _listdir(path: str) -> list[str]:
return listdir(path)

@classmethod
@extend_schema(
request=None,
Expand Down Expand Up @@ -58,7 +64,7 @@ def get(cls, request, selector: str):
return Response(data={'msg': 'Base directory does not exist'}, status=404)

items = {'files': [], 'directories': []}
raw_items = listdir(path_check)
raw_items = cls._listdir(path_check)

for item in raw_items:
item_path = Path(os_path.join(path_check, item))
Expand Down

0 comments on commit 12dc5bb

Please sign in to comment.