Daily Tech Briefing
AI 科技速览

每天 5 分钟内学习 AI。获取最新的人工智能新闻,理解其重要性,并学习如何将其应用于您的工作。

AI 快讯
Dev.to AI · 2026/8/4 16:46:18

Optimizing TV Dashboard Refresh in CraveView: From 30 s to 15 min to Keep Neon Scale‑to‑Zero

AI 中文解读
CraveView团队把电视看板的自动刷新间隔从30秒大幅拉长到15分钟,云数据库费用直降80%,用户刷剧体验却一点没受影响。核心逻辑很简单:原来每30秒就唤醒一次数据库查询最新节目单,相当于每半分钟去摇醒一次熟睡的朋友问"有啥新消息吗"——但电视节目排期一天也变不了几次,纯属浪费。改成15分钟刷新后,数据库能在空闲时真正"闭眼休息",按秒计费的云端账单自然大幅缩水。这项改动看似只是个技术参数调整,却给普通用户和开发者提了个醒:日常应用里很多"勤快"的自动刷新其实没必要。以后流媒体、新闻类App若能学这套思路,后台消耗降低,运营成本省下来,订阅价格就可能更亲民;同时你的手机和电视也不会因为频繁请求数据而白白耗电发热,看片更省心。
<h1> Optimizing TV Dashboard Refresh in CraveView: From 30 s to 15 min to Keep Neon Scale‑to‑Zero </h1> <p><strong>TL;DR:</strong><br><br> I bumped the TV dashboard auto‑refresh interval from 30 s to 5 min and later to 15 min to give Neon’s serverless database a chance to scale‑to‑zero, cutting compute costs by ~80 % without sacrificing user experience. The change is just a single constant in <code>src/features/tv/TVDashboard.tsx</code>, but it required rethinking our polling strategy and documenting the incident in <code>CLAUDE.md</code> and <code>CLAUDE_CODE_CONTEXT.md</code>.</p> <h2> The Problem </h2> <p>Running the TV dashboard on a Vercel‑hosted front‑end with a Neon PostgreSQL backend, we hit a recurring performance spike. Every 30 seconds the client sent a GraphQL query to fetch the latest TV schedule, which in turn triggered Neon to wake up its compute instance. Neon’s cost model is per‑second billing, so a 30 s polling loop caused the database to stay awake for a significant portion of the day, even when no user was actively viewing the dashboard. The symptom was twofold:</p> <ol> <li> <strong>Higher bill:</strong> Neon compute charges rose by ~30 % compared to the previous month.</li> <li> <strong>Unnecessary load:</strong> The database was waking up for every client that had the dashboard open, even if the data had not changed.</li> </ol> <p>The error log from Neon’s monitoring dashboard looked like this:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>2026-08-02 14:12:05 UTC | neon | INFO | Wake‑up triggered by query: SELECT * FROM tv_schedule; </code></pre> </div> <p>The goal was to reduce the number of wake‑ups while keeping the UI responsive enough for users.</p> <h2> What I Tried First </h2> <p>Initially, I considered two approaches:</p> <ol> <li><p><strong>Client‑side caching:</strong> Store the fetched data in <code>localStorage</code> and only re‑query if the cache was older than a minute.<br><br> <em>Result:</em> The UI became stale after a user refreshed the page, and we still hit the database on the first load.</p></li> <li><p><strong>Server‑side polling endpoint:</strong> Move the polling logic to a Vercel Edge function that would run every minute and push updates via WebSockets.<br><br> <em>Result:</em> Added complexity, increased cold‑start latency, and required a new WebSocket layer that didn't fit the current architecture.</p></li> </ol> <p>Both options were overkill for a relatively simple “schedule” page that rarely changes more than once per day. I realized the root cause was the aggressive 30 s interval.</p> <h2> The Implementation </h2> <h3> 1. Adjusting the Refresh Interval </h3> <p>I refactored the constant in <code>src/features/tv/TVDashboard.tsx</code>:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight tsx"><code><span class="c1">// src/features/tv/TVDashboard.tsx</span> <span class="kr">interface</span> <span class="nx">DashboardData</span> <span class="p">{</span> <span class="c1">// ...</span> <span class="p">}</span> <span class="o">-</span><span class="kd">const</span> <span class="nx">REFRESH_MS</span> <span class="o">=</span> <span class="mi">30</span><span class="nx">_000</span><span class="p">;</span> <span class="c1">// 30s — previously set for real‑time feel</span> <span class="o">+</span><span class="kd">const</span> <span class="nx">REFRESH_MS</span> <span class="o">=</span> <span class="mi">300</span><span class="nx">_000</span><span class="p">;</span> <span class="c1">// 5min — data only changes on manual sync, no need to poll faster</span> </code></pre> </div> <p>After the first change, we observed a drop in Neon wake‑ups to about 5 % of the previous count. Users reported no noticeable delay in data freshness because the TV schedule rarely changes.</p> <h3> 2. Bumping to 15 min for Compute Headroom </h3> <p>The Neon incident o
分享
阅读原文