Skip to content

Commit

Permalink
Add action to delete empty threads
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwardy committed Jan 15, 2024
1 parent 77e53b9 commit acaf674
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion app/blueprints/admin/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from sqlalchemy import or_, and_

from app.models import PackageRelease, db, Package, PackageState, PackageScreenshot, MetaPackage, User, \
NotificationType, PackageUpdateConfig, License, UserRank, PackageType
NotificationType, PackageUpdateConfig, License, UserRank, PackageType, Thread
from app.tasks.emails import send_pending_digests
from app.tasks.forumtasks import import_topic_list, check_all_forum_accounts
from app.tasks.importtasks import import_repo_screenshot, check_zip_release, check_for_updates, update_all_game_support
Expand Down Expand Up @@ -347,3 +347,17 @@ def import_screenshots():
import_repo_screenshot.delay(package.id)

return redirect(url_for("admin.admin_page"))


@action("DANGER: Delete empty threads")
def delete_empty_threads():
query = Thread.query.filter(~Thread.replies.any())
count = query.count()
for thread in query.all():
thread.watchers.clear()
db.session.delete(thread)
db.session.commit()

flash(f"Deleted {count} threads", "success")

return redirect(url_for("admin.admin_page"))

0 comments on commit acaf674

Please sign in to comment.