Sveltekit Blog Engine
Guestbook
Login
Read in:
English日本語한국어

Overdue Tech Debt: Notes on a Marathon Cleanup

dev-notes • 2026-10-13 AM11:26:16 (GMT+9) • 👀 0 •
#Vibe Coding#Tech Debt#Troubleshooting#Cloudflare D1
  1. While checking the post list on the admin page, I noticed a bizarre issue where view counts were completely out of sync.
    There were posts I had personally read, and posts visited by actual users, yet the view counts displayed on the blog frontend, the admin dashboard, and the post management list were all completely different.
    For a moment, I broke into a cold sweat thinking a deployment might have wiped out a column or an entire table in the D1 database.

  2. In a panic, I opened a remote D1 terminal to inspect the table schema and actual data, but the result was surprisingly anticlimactic.

    npx wrangler d1 execute svelteblog-db --remote --command="PRAGMA table_info(posts);"

    The view_count column in the posts table was perfectly intact, and checking the user DB revealed over 1,000 daily view logs totaling more than 1,400 views, safe and sound.
    The data hadn't vanished at all; it was breathing just fine in the database, only invisible on the frontend.

  3. Tracing back the root cause revealed fragmented pieces left behind while rushing through features with "vibe coding" without cleaning up along the way.
    In our blog architecture, the database is split into BLOG_DB (post content) and USER_DB (user data and analytics logs). The daily view logging logic was implemented fine, but the sync pipeline to aggregate those stats into the post cache column was left unfinished with a casual thought of "well, it runs without errors." That was the debt.
    Real data was accumulating in the user DB, while the admin panel was staring blankly at the empty cache column in the blog DB, so showing 0 was inevitable.

  4. Thinking "Aha, found the bug!", I updated the admin server code to aggregate totals from the user DB, map them properly, and auto-sync mismatched posts back into the blog DB, then deployed the changes.

    // Admin server: Aggregate USER_DB raw views and auto-sync mismatched posts
    const { results: viewResults } = await userDb.prepare(`
        SELECT post_id, SUM(views) as total_views FROM post_views GROUP BY post_id
    `).all();
    
    const posts = (postsRaw || []).map((p: any) => ({
        ...p,
        view_count: viewCountMap[p.id] ?? (p.view_count || 0)
    }));

    Now proper numbers like 41 views should have appeared... but even after refreshing, it stubbornly stayed at 0.
    Direct queries to D1 clearly showed 41, yet the web page adamantly insisted on displaying 0. It genuinely felt like a ghost in the machine.

  5. As it turned out, the culprit wasn't just the server; another issue was lurking inside the frontend Svelte component.
    A while ago, I had added localStorage caching to make the admin post list load faster, and that was the trap.

    // apps/admin/src/routes/posts/+page.svelte (problematic code before fix)
    } else {
        // Normal entry: reuse valid cache from localStorage if available
        const saved = localStorage.getItem(POSTS_CACHE_KEY);
        if (saved) {
            cachedPosts = parsed.posts; // <- Blindly overwrites fresh server data with stale localStorage cache
        }
    }

    Inside Svelte 5's $effect, the moment the server fetched the fresh count of 41 from D1 and handed it to the client, the frontend code immediately pulled the stale list with 0 views from browser storage and plastered it over the screen.
    Because there was no expiration time (TTL), no matter how many times you hammered F5, the browser faithfully rendered the stale cache. There was no way the screen would update.

  6. In the end, incomplete backend data sync met ruthless frontend localStorage overwrites, creating a bizarre collaboration where "both server and DB are intact, but the browser actively overwrites the screen."
    Once I ripped out the aggressive localStorage overwrite logic and pointed the UI directly to fresh server data, 41 finally showed up crystal clear.
    Vibe coding alongside AI to churn out features fast is great, but when developers don't understand the whole picture and just let things run, these fragments slip by unnoticed. If you don't clean them up in time, they eventually bite you from the strangest angles.

  7. Testing right after a fresh setup is tough to begin with, and leaving the entire coding process to AI reminded me that while everything is fine when it works, diagnosing issues when things break can become a real headache.
    I was planning to touch up the design editor once things stabilized reasonably well, but I have an ominous feeling that reaching that "reasonable" bar might take quite some time.
    Should I just wait for AI capabilities to accelerate even further...?

  8. Vibe coding has already become mainstream, and it comes with a serious side effect: once you experience it, there's no going back.
    While we still need human developers to orchestrate the big picture today, I know deep down that the day when you just say "build this" and AI handles all the coordination autonomously isn't far off.
    Every time I feel that shift firsthand, it leaves me with quite a bittersweet feeling.

Share this post on social networks

0 Comments

Login is required to write comments.

This post is written in English.

Are you sure you want to delete?

This post is written in English.

Popular Tags

#API Token#AccountRestriction#AdSense#Admin#Animation#Anonymization#AutoPublishing#Automation#Backup#Backup & Restore
1 / 10

Popular Posts

  • Cloudflare Wrangler Login and API Token Configuration Guide in CLI Environments
    2026-07-15 PM9:17:34 (GMT+9)
  • Engineering SKBE: Multi-Slot Design, D1 Cache Optimization, and SEO Normalization (v1.0.0.11 ~ v1.0.0.13)
    2026-09-08 AM11:58:10 (GMT+9)
  • CMD One-Click Installation & Cloudflare Deployment Guide
    2026-07-15 PM9:19:35 (GMT+9)

Popular Tags

#API Token#AccountRestriction#AdSense#Admin#Animation#Anonymization#AutoPublishing#Automation#Backup#Backup & Restore
1 / 10

후원

Github

Categories

  • Admin Guide (5)
  • Detailed Manual (4)
  • DevLog (11)
  • DevNotes (4)
  • General Guide (3)
  • User Guide (3)

Recent Posts

  • Overdue Tech Debt: Notes on a Marathon Cleanup
    2026-10-13 AM11:26:16 (GMT+9)
  • Finding an Anomaly in CFA
    2026-10-12 AM10:07:39 (GMT+9)
  • Switching Default Analytics to CFA
    2026-10-08 PM11:46:03 (GMT+9)

Popular Posts

  • Cloudflare Wrangler Login and API Token Configuration Guide in CLI Environments
    2026-07-15 PM9:17:34 (GMT+9)
  • Engineering SKBE: Multi-Slot Design, D1 Cache Optimization, and SEO Normalization (v1.0.0.11 ~ v1.0.0.13)
    2026-09-08 AM11:58:10 (GMT+9)
  • CMD One-Click Installation & Cloudflare Deployment Guide
    2026-07-15 PM9:19:35 (GMT+9)

Support the project ☕

Github Link

AboutPrivacy PolicyContactTerms of Service

© 2026 스벨트킷 블로그 엔진 · Powered by Sveltekitblog Engine on Svelte 5

RSS SKBE v1.0.1.2 Share Design