Skip to content

Commit

Permalink
client: allow query for delete_contributions
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaume committed Oct 16, 2021
1 parent 5e3ab38 commit c703586
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions mpcontribs-client/mpcontribs/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,19 +857,26 @@ def init_columns(self, name: str, columns: dict) -> dict:
self.projects.update_entry(pk=name, project={"columns": []}).result()
return self.projects.update_entry(pk=name, project=payload).result()

def delete_contributions(self, name: str):
"""Remove all contributions for a project
def delete_contributions(
self,
name: str,
query: dict = None,
timeout: int = -1
):
"""Remove all contributions for a project and query
Note: This also resets the columns field for a project. It might have to be
re-initialized via `client.init_columns()`.
Args:
name (str): name of the project for which to delete contributions
query (dict): optional query to select contributions
timeout (int): cancel remaining requests if timeout exceeded (in seconds)
"""
tic = time.perf_counter()
# reset columns to be save (sometimes not all are reset BUGFIX?)
self.projects.update_entry(pk=name, project={"columns": []}).result()
cids = list(self.get_all_ids(dict(project=name)).get(name, {}).get("ids", set()))
query = query or {}
query["project"] = name
cids = list(self.get_all_ids(query).get(name, {}).get("ids", set()))

if not cids:
print(f"There aren't any contributions to delete for {name}")
Expand All @@ -880,8 +887,8 @@ def delete_contributions(self, name: str):
_, total_pages = self.get_totals(query=query)
queries = self._split_query(query, op="delete", pages=total_pages)
futures = [self._get_future(i, q, op="delete") for i, q in enumerate(queries)]
_run_futures(futures, total=total)
left, _ = self.get_totals(query=dict(project=name))
_run_futures(futures, total=total, timeout=timeout)
left, _ = self.get_totals(query=query)
deleted = total - left
self._load()
toc = time.perf_counter()
Expand Down

0 comments on commit c703586

Please sign in to comment.