Publish reviewed history-free open-source snapshot (2026-10-12)

This commit is contained in:
Zonghengjia Open Source
2026-10-11 23:23:20 +00:00
commit 901f27baf5
301 changed files with 32378 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
"""Shared lock order for subscription counters; daily rows remain the ledger."""
from django.db import connection
from .models import Subscription
def non_key_lock_options():
# PostgreSQL FOR UPDATE conflicts with FK key-share checks on new ledger
# rows. We change counters, not primary keys, so NO KEY UPDATE is sufficient.
return {"no_key": True} if connection.features.has_select_for_no_key_update else {}
def lock_usage_subscriptions(subscription_ids):
# Call inside an atomic transaction, before aggregation or ledger updates.
# A consistent order is necessary when two nodes report the same accounts
# in opposite payload orders.
return list(Subscription.objects.filter(pk__in=set(subscription_ids)).order_by("pk")
.select_for_update(**non_key_lock_options()))