Reworked search to optimize a bit.
This commit is contained in:
@@ -34,11 +34,12 @@ def do_recursive_search(start_path, query):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Get all sub-dirs and images that match the query.
|
# Get all sub-dirs and images that match the query.
|
||||||
subdirs = sorted([i.absolute() for i in start_path.iterdir() if i.is_dir() and query.lower() in i.name.lower()])
|
all_subdirs = sorted([i for i in start_path.iterdir() if i.is_dir()])
|
||||||
images = sorted([i for i in start_path.iterdir() if i.is_file() and filetype.is_image(str(i)) and query.lower() in i.name.lower()])
|
subdirs = sorted([i for i in all_subdirs if query.lower() in i.name.lower()])
|
||||||
|
images = sorted([i for i in start_path.iterdir() if i.is_file() and query.lower() in i.name.lower()])
|
||||||
|
|
||||||
# For all sub-directories, regardless of the query.
|
# For all sub-directories, regardless of the query.
|
||||||
for subdir in sorted([i for i in start_path.iterdir() if i.is_dir()]):
|
for subdir in all_subdirs:
|
||||||
# Do a recursive search.
|
# Do a recursive search.
|
||||||
rec_subdirs, rec_images = do_recursive_search(subdir, query.lower())
|
rec_subdirs, rec_images = do_recursive_search(subdir, query.lower())
|
||||||
|
|
||||||
@@ -94,6 +95,9 @@ def gallery_view(request, path = None):
|
|||||||
# If there is a search query then search the current directory recursively.
|
# If there is a search query then search the current directory recursively.
|
||||||
subdirs, images = do_recursive_search(full_path, search)
|
subdirs, images = do_recursive_search(full_path, search)
|
||||||
|
|
||||||
|
# Only keep image files.
|
||||||
|
images = [image for image in images if filetype.is_image(str(image))]
|
||||||
|
|
||||||
# For every sub-directory found, prepare it's name and path for rendering.
|
# For every sub-directory found, prepare it's name and path for rendering.
|
||||||
subdir_data = []
|
subdir_data = []
|
||||||
for subdir in subdirs:
|
for subdir in subdirs:
|
||||||
|
Reference in New Issue
Block a user