From 6fe825620891e62c20aedc2ce2717d905956a06a Mon Sep 17 00:00:00 2001 From: Mircea Lungu Date: Sat, 1 Aug 2026 23:36:34 +0300 Subject: [PATCH] Friend-share: warm tokenization cache at send, for instant recipient open MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The recipient's derivative is generated in the background at send time; warm its Stanza/MWE tokenization cache in the same job (via get_tokenized_content, which caches on a miss) so the recipient's first open is instant instead of paying tokenization then. Best-effort — a warm-up failure never fails the share. Co-Authored-By: Claude Opus 4.8 --- zeeguu/api/endpoints/friends.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/zeeguu/api/endpoints/friends.py b/zeeguu/api/endpoints/friends.py index cd970e71..753b68c5 100644 --- a/zeeguu/api/endpoints/friends.py +++ b/zeeguu/api/endpoints/friends.py @@ -516,6 +516,17 @@ def _generate_recipient_derivative(article, recipient, delivery_language, level) log(f"share to user_id={recipient.id}: derivative generation failed; " f"recipient will open the canonical article") return None + + # Warm the reader's tokenization cache now, in this same background job, so + # the recipient's first open is instant instead of paying the Stanza/MWE + # tokenization cost then. get_tokenized_content() caches on a miss. Best + # effort — a warm-up failure must not fail the share. + try: + derivative.get_tokenized_content() + except Exception as e: + log(f"share to user_id={recipient.id}: tokenization warm-up failed " + f"(non-fatal): {e}") + return derivative.id