From c61b2b403537645b34ec88eedce650dd4a16ff8f Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Fri, 18 Jun 2021 00:41:30 +1000 Subject: [PATCH] browsing by folders should now only load contents of cwd from DB, faster, also removes bugs of that content not being in first 50 entries --- files.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/files.py b/files.py index 5357ae4..7cb6bd3 100644 --- a/files.py +++ b/files.py @@ -197,7 +197,9 @@ def files_ip(): else: entries+=Entry.query.join(File).join(EntryDirLink).join(Dir).join(PathDirLink).join(Path).filter(Path.path_prefix==prefix).order_by(File.year.desc(),File.month.desc(),File.day.desc(),Entry.name).offset(offset).limit(how_many).all() - entries+=Entry.query.join(Dir).join(PathDirLink).join(Path).filter(Path.path_prefix==prefix).order_by(Entry.name).offset(offset).limit(how_many).all() + + if folders: + entries+=Entry.query.join(Dir).join(PathDirLink).join(Path).filter(Path.path_prefix==prefix).order_by(Entry.name).all() return render_template("files.html", page_title='View Files (Import Path)', entry_data=entries, noo=noo, grouping=grouping, how_many=how_many, offset=offset, size=size, folders=folders, cwd=cwd, root=root ) @@ -215,12 +217,29 @@ def files_sp(): for path in paths: prefix = SymlinkName("Storage",path,path+'/') - if noo == "Oldest": - entries+=Entry.query.join(File).join(EntryDirLink).join(Dir).join(PathDirLink).join(Path).filter(Path.path_prefix==prefix).order_by(File.year,File.month,File.day,Entry.name).offset(offset).limit(how_many).all() + if folders: + # okay the root cwd is fake, so treat it specially - its Dir can be found by path with dir.rel_path='' + if cwd == 'static/Storage': + dir=Entry.query.join(Dir).join(PathDirLink).join(Path).filter(Dir.rel_path=='').filter(Path.path_prefix==prefix).order_by(Entry.name).first() + # although this is 1 entry, needs to come back via all() to be iterable + entries+= Entry.query.filter(Entry.id==dir.id).all() + else: + rp = cwd.replace( prefix, '' ) + # when in subdirs, replacing prefix will leave the first char as /, get rid of it + if len(rp) and rp[0] == '/': + rp=rp[1:] + dir=Entry.query.join(Dir).join(PathDirLink).join(Path).filter(Dir.rel_path==rp).filter(Path.path_prefix==prefix).order_by(Entry.name).first() + entries+= Entry.query.join(EntryDirLink).filter(EntryDirLink.dir_eid==dir.id).order_by(Entry.name).all() + if noo == "Oldest": + entries+=Entry.query.join(File).join(EntryDirLink).filter(EntryDirLink.dir_eid==dir.id).order_by(File.year,File.month,File.day,Entry.name).offset(offset).limit(how_many).all() + else: + entries+=Entry.query.join(File).join(EntryDirLink).filter(EntryDirLink.dir_eid==dir.id).order_by(File.year.desc(),File.month.desc(),File.day.desc(),Entry.name).offset(offset).limit(how_many).all() else: - entries+=Entry.query.join(File).join(EntryDirLink).join(Dir).join(PathDirLink).join(Path).filter(Path.path_prefix==prefix).order_by(File.year.desc(),File.month.desc(),File.day.desc(),Entry.name).offset(offset).limit(how_many).all() + if noo == "Oldest": + entries+=Entry.query.join(File).join(EntryDirLink).join(Dir).join(PathDirLink).join(Path).filter(Path.path_prefix==prefix).order_by(File.year,File.month,File.day,Entry.name).offset(offset).limit(how_many).all() + else: + entries+=Entry.query.join(File).join(EntryDirLink).join(Dir).join(PathDirLink).join(Path).filter(Path.path_prefix==prefix).order_by(File.year.desc(),File.month.desc(),File.day.desc(),Entry.name).offset(offset).limit(how_many).all() - entries+=Entry.query.join(Dir).join(PathDirLink).join(Path).filter(Path.path_prefix==prefix).order_by(Entry.name).offset(offset).limit(how_many).all() return render_template("files.html", page_title='View Files (Storage Path)', entry_data=entries, noo=noo, grouping=grouping, how_many=how_many, offset=offset, size=size, folders=folders, cwd=cwd, root=root ) @@ -349,7 +368,6 @@ def rm_dups(): def restore_files(): jex=[] for el in request.form: - print( f"{el}={request.form[el]}" ) jex.append( JobExtra( name=f"{el}", value=request.form[el] ) ) job=NewJob( "restore_files", 0, None, jex )