Skip to content

Commit

Permalink
Improve processing time for deleting beliefs via CLI (#1005)
Browse files Browse the repository at this point in the history
* speed up deleting beliefs via CLI

Signed-off-by: Ahmad Wahid <ahmedwahid16101@gmail.com>

* docs: changelog entry

Signed-off-by: F.N. Claessen <felix@seita.nl>

* fix: typo

Signed-off-by: F.N. Claessen <felix@seita.nl>

---------

Signed-off-by: Ahmad Wahid <ahmedwahid16101@gmail.com>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Co-authored-by: F.N. Claessen <felix@seita.nl>
  • Loading branch information
Ahmad-Wahid and Flix6x committed Mar 11, 2024
1 parent 489e2bb commit 4e52b9f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
2 changes: 1 addition & 1 deletion documentation/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ New features
Infrastructure / Support
----------------------


* Improve processing time for deleting beliefs via CLI [see `PR #1005 <https://github.com/FlexMeasures/flexmeasures/pull/1005>`_]


v0.19.2 | March 1, 2024
Expand Down
9 changes: 1 addition & 8 deletions flexmeasures/cli/data_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,7 @@ def delete_beliefs( # noqa: C901
elif generic_assets:
prompt = f"Delete all {num_beliefs_up_for_deletion} beliefs on sensors of {join_words_into_a_list([repr(asset) for asset in generic_assets])}?"
click.confirm(prompt, abort=True)

# Delete all beliefs found by query
beliefs_up_for_deletion = db.session.scalars(q).all()
batch_size = 10000
for i, b in enumerate(beliefs_up_for_deletion, start=1):
if i % batch_size == 0 or i == num_beliefs_up_for_deletion:
click.echo(f"{i} beliefs processed ...")
db.session.delete(b)
db.session.execute(delete(TimedBelief).where(*entity_filters, *event_filters))
click.secho(f"Removing {num_beliefs_up_for_deletion} beliefs ...")
db.session.commit()
num_beliefs_after = db.session.scalar(select(func.count()).select_from(q))
Expand Down
2 changes: 1 addition & 1 deletion flexmeasures/data/models/planning/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
def app_with_each_solver(app, request):
"""Set up the app config to run with different solvers.
A test that uses this fixtures runs all of its test cases with HiGHS and then again with Cbc.
A test that uses this fixture runs all of its test cases with HiGHS and then again with Cbc.
"""
original_solver = app.config["FLEXMEASURES_LP_SOLVER"]
app.config["FLEXMEASURES_LP_SOLVER"] = request.param
Expand Down

0 comments on commit 4e52b9f

Please sign in to comment.