quick-filter: use a dedicated method for fetching quick filter nodes.

This code needs a fast and dedicated method for this. We'll re-implement it and
we don't want to change existing API. So it's just a start to have a duplicated
method that will be rewritten.
This commit is contained in:
Marcin Kuzminski 2019-09-09 14:06:01 +02:00
parent 51c6861d06
commit 2180d8010a
3 changed files with 38 additions and 3 deletions

View file

@ -920,8 +920,7 @@ class RepoFilesView(RepoAppView):
log.debug('Generating cached nodelist for repo_id:%s, %s, %s',
repo_id, commit_id, f_path)
try:
_d, _f = ScmModel().get_nodes(
repo_name, commit_id, f_path, flat=False)
_d, _f = ScmModel().get_quick_filter_nodes(repo_name, commit_id, f_path)
except (RepositoryError, CommitDoesNotExistError, Exception) as e:
log.exception(safe_str(e))
h.flash(safe_str(h.escape(e)), category='error')

View file

@ -667,7 +667,7 @@ class DirNode(Node):
"""
DirNode stores list of files and directories within this node.
Nodes may be used standalone but within repository context they
lazily fetch data within same repositorty's commit.
lazily fetch data within same repository's commit.
"""
def __init__(self, path, nodes=(), commit=None):

View file

@ -583,6 +583,42 @@ class ScmModel(BaseModel):
return _dirs, _files
def get_quick_filter_nodes(self, repo_name, commit_id, root_path='/'):
"""
Generate files for quick filter in files view
"""
_files = list()
_dirs = list()
try:
_repo = self._get_repo(repo_name)
commit = _repo.scm_instance().get_commit(commit_id=commit_id)
root_path = root_path.lstrip('/')
for __, dirs, files in commit.walk(root_path):
for f in files:
_data = {
"name": h.escape(f.unicode_path),
"type": "file",
}
_files.append(_data)
for d in dirs:
_data = {
"name": h.escape(d.unicode_path),
"type": "dir",
}
_dirs.append(_data)
except RepositoryError:
log.exception("Exception in get_quick_filter_nodes")
raise
return _dirs, _files
def get_node(self, repo_name, commit_id, file_path,
extended_info=False, content=False, max_file_bytes=None, cache=True):
"""