Commit 5f0e3528 authored by Thomas Lotze's avatar Thomas Lotze

re #22: preselect listed projects by searching for group and project

This is no replacement for applying the filters later but speeds up
project retrieval noticeably for large Gitlab instances.
parent f12b5346
......@@ -38,10 +38,12 @@ logging.basicConfig(format=logging.BASIC_FORMAT)
help='Filter for projects in group',
help='Filter for project name',
......@@ -12,30 +12,35 @@ def fetch(url, token, filter):
gitlab = Gitlab(url, token)
projects = gitlab.projects.list(all=True)
projects.sort(key=lambda p: p.path_with_namespace)
# We iterate over all projects regardless of our filter settings. When
# We iterate over all projects loosely matching group and project filters
# and then apply the filters in a more precisely defined manner. When
# filtering for a group, we cannot list all groups first; if we try to do
# so, Gitlab will only return groups associated with the api token. When
# filtering for a project name, we have no better way of searching a
# project by name. When filtering for a user, we have no way at all of
# filtering for a project name, we have no way of searching a project
# by exact name. When filtering for a user, we have no way at all of
# querying all notes authored by that user. As we want to catch all time
# spent by the user in the past regardless of their then or present
# affiliations with groups, projects, issues etc, we won't try to be
# clever and optimise here, even if this results in a full-database scan.
# Let's see whether we'll be forced to optimise by production data.
pattern = ' '.join((filter['group'], filter['project']))
projects = gitlab.projects.list(
search=pattern, search_namespaces=True, all=True)
projects.sort(key=lambda p: p.path_with_namespace)
for project in projects:
if filter['project'] not in (,
if filter['group'] not in (
yield project, fetch_project(project, filter)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment