Page MenuHomeMusing Studio

Update post view counts in batches
Closed, ResolvedPublic

Description

Overview

Every time a post is loaded, we update that post's view_count in the database.

Background

This happens in a goroutine, ensuring post rendering is still fast. But it can cause additional load on the database and block future requests on engines where it matters (like SQLite).

Implementation

Instead of doing view_count = view_count + 1 every time we serve a post, we should temporarily keep track of additional views in memory, and then write that data to the database after a short interval (e.g. 5 seconds).

Revisions and Commits

Event Timeline

matt triaged this task as Low priority.Dec 3 2018, 4:16 PM
matt created this task.
matt created this object with visibility "Public (No Login Required)".
matt created this object with edit policy "All Users".

This is more important on Write.as now, especially with replica MySQL databases that have become increasingly laggy.

matt raised the priority of this task from Low to Medium-High.Dec 13 2021, 5:32 PM
matt added a commit: Restricted Diffusion Commit.Dec 13 2021, 6:10 PM
matt added a commit: Restricted Diffusion Commit.
matt added a commit: Restricted Diffusion Commit.
matt added a commit: Restricted Diffusion Commit.

Just deployed on Write.as, and seems to be running smoothly. The real test will be tonight through tomorrow morning, when we see our normal influx of traffic.

matt added a commit: Restricted Diffusion Commit.Dec 14 2021, 3:28 PM
matt added a commit: Restricted Diffusion Commit.
matt added a commit: Restricted Diffusion Commit.Dec 31 2021, 10:24 PM
matt removed a project: WriteFreely.

This is running well and doing the job. WF implementation will be handled in T891.