mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-03 03:37:28 +01:00
Remove package deletion to worker
This commit is contained in:
parent
e1e77033fe
commit
2d29fb1994
@ -305,33 +305,18 @@ def do_notify_git_forums_links():
|
||||
return redirect(url_for("tasks.check", id=task_id, r=url_for("admin.admin_page")))
|
||||
|
||||
|
||||
def handle_delete_packages(query):
|
||||
count = query.count()
|
||||
for pkg in query.all():
|
||||
pkg.review_thread = None
|
||||
db.session.delete(pkg)
|
||||
db.session.commit()
|
||||
|
||||
clean_uploads()
|
||||
|
||||
flash("Deleted {} soft deleted packages packages".format(count), "success")
|
||||
return redirect(url_for("admin.admin_page"))
|
||||
|
||||
|
||||
@action("DANGER: Delete less popular removed packages")
|
||||
def del_less_popular_removed_packages():
|
||||
one_year_ago = datetime.datetime.now() - datetime.timedelta(days=365)
|
||||
query = Package.query.filter(
|
||||
Package.state == PackageState.DELETED,
|
||||
Package.downloads < 1000,
|
||||
~Package.audit_log_entries.any(AuditLogEntry.created_at > one_year_ago))
|
||||
return handle_delete_packages(query)
|
||||
task_id = uuid()
|
||||
clear_removed_packages.apply_async((False, ), task_id=task_id)
|
||||
return redirect(url_for("tasks.check", id=task_id, r=url_for("admin.admin_page")))
|
||||
|
||||
|
||||
@action("DANGER: Delete all removed packages")
|
||||
def del_removed_packages():
|
||||
query = Package.query.filter_by(state=PackageState.DELETED)
|
||||
return handle_delete_packages(query)
|
||||
task_id = uuid()
|
||||
clear_removed_packages.apply_async((True, ), task_id=task_id)
|
||||
return redirect(url_for("tasks.check", id=task_id, r=url_for("admin.admin_page")))
|
||||
|
||||
|
||||
@action("DANGER: Check all releases (postReleaseCheckUpdate)")
|
||||
|
@ -14,11 +14,12 @@
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import datetime
|
||||
import re
|
||||
|
||||
from sqlalchemy import or_, and_
|
||||
|
||||
from app.models import Package, db, PackageState
|
||||
from app.models import Package, db, PackageState, AuditLogEntry
|
||||
from app.tasks import celery
|
||||
from app.utils import post_bot_message
|
||||
|
||||
@ -82,3 +83,23 @@ def notify_about_git_forum_links():
|
||||
post_bot_message(package, title, msg)
|
||||
|
||||
db.session.commit()
|
||||
|
||||
|
||||
@celery.task()
|
||||
def clear_removed_packages(all_packages: bool):
|
||||
if all_packages:
|
||||
query = Package.query.filter_by(state=PackageState.DELETED)
|
||||
else:
|
||||
one_year_ago = datetime.datetime.now() - datetime.timedelta(days=365)
|
||||
query = Package.query.filter(
|
||||
Package.state == PackageState.DELETED,
|
||||
Package.downloads < 1000,
|
||||
~Package.audit_log_entries.any(AuditLogEntry.created_at > one_year_ago))
|
||||
|
||||
count = query.count()
|
||||
for pkg in query.all():
|
||||
pkg.review_thread = None
|
||||
db.session.delete(pkg)
|
||||
db.session.commit()
|
||||
|
||||
return f"Deleted {count} soft deleted packages packages"
|
||||
|
Loading…
Reference in New Issue
Block a user