feat(versions): prune_auto_pins FIFO-trims auto-pinned bucket
Auto-pinned versions live in their own bucket with MAX_AUTO_PINS=25 cap. The scan job calls this after each note's promotions complete; the oldest auto-pinned rows are dropped past the cap. Manual pins and rolling rows are untouched.
This commit is contained in:
@@ -88,3 +88,32 @@ async def unpin_version(
|
||||
await session.commit()
|
||||
await session.refresh(version)
|
||||
return version
|
||||
|
||||
|
||||
async def prune_auto_pins(user_id: int, note_id: int) -> None:
|
||||
"""FIFO-prune the auto-pinned bucket for one note past MAX_AUTO_PINS.
|
||||
|
||||
Manual pins and rolling rows are untouched. Called by the scan job
|
||||
after each note's auto-pin promotions finish.
|
||||
"""
|
||||
async with async_session() as session:
|
||||
await session.execute(
|
||||
text(
|
||||
"""
|
||||
DELETE FROM note_versions
|
||||
WHERE id IN (
|
||||
SELECT id FROM note_versions
|
||||
WHERE note_id = :note_id
|
||||
AND user_id = :user_id
|
||||
AND pin_kind = 'auto'
|
||||
ORDER BY created_at DESC
|
||||
OFFSET :max_auto_pins
|
||||
)
|
||||
"""
|
||||
).bindparams(
|
||||
note_id=note_id,
|
||||
user_id=user_id,
|
||||
max_auto_pins=MAX_AUTO_PINS,
|
||||
)
|
||||
)
|
||||
await session.commit()
|
||||
|
||||
Reference in New Issue
Block a user