Merge remote-tracking branch 'gitea/main' into e5-s3-toolbar-relocation

This commit is contained in:
2026-08-17 22:14:50 +02:00
4 changed files with 97 additions and 1 deletions
+10
View File
@@ -14,6 +14,14 @@ from app.models import Notification
# rows are never pruned (the user hasn't seen them yet).
READ_SOFT_CAP = 200
# Hard limit of the Notification.title column, read straight from the model so the clamp
# can never drift from the actual column width (a later migration is the single source of
# truth). Titles are only an English fallback — the client renders the translated message
# from `data` — so clamping an over-long one (e.g. a FB/IG reel whose "title" is the whole
# caption, hundreds of chars) is harmless to the UI and prevents a StringDataRightTruncation
# that would abort the caller's whole transaction (the batched download_gc run in particular).
TITLE_MAX_LEN = Notification.__table__.c.title.type.length
def create_notification(
db: Session,
@@ -27,6 +35,8 @@ def create_notification(
) -> Notification:
"""Insert one notification for a user. Callers that batch many inserts in a single
transaction can pass commit=False and commit once themselves."""
if title is not None and len(title) > TITLE_MAX_LEN:
title = title[: TITLE_MAX_LEN - 1] + "…" # clamp to the column limit, add an ellipsis
notif = Notification(
user_id=user_id, type=type, title=title, body=body, data=data
)