Performance: every page view reads, decodes and rewrites the whole view counter under one lock

Open
#677 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@guidol-ive is already working on this.

Since Oct 28, 2026.

  • #678 by @guidol-ive — open

Assessment

Difficulty
4/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Stale
Tech stack
php

Research direction

Read base.php at hypha_incrementStats() and hypha_getStats(), then trace how flushDigest() consumes the counter. Check the existing handling of data/hypha.stats and the proposed data/hypha.stats.log behavior, including period boundaries and cleanup. Done means views append short period timestamps and digest reads add and discard reported periods; pull request #678 is already open against this issue.

Written by the indexing model from the issue text.

Description

Impact: Medium Level: Easy Type: Bug Value: Visitors

Part of #411.

Problem

Every page view by a visitor runs hypha_incrementStats() (base.php), which:

  1. takes an exclusive lock on data/hypha.stats;
  2. reads and decodes the whole JSON file;
  3. adds one;
  4. writes the whole file back through a temporary file and rename().

All views of the site wait for each other on that one lock, and the file grows with every digest period. Under load on a bind mount (Docker Desktop on macOS), the rename() also briefly hides the file from a parallel fopen(), which then fails with a 500 (Cannot lock file data/hypha.stats, open failed).

The count is only read once per digest period, by flushDigest() through hypha_getStats().

Proposal

  • Append one short line (the timestamp of the period) per view to data/hypha.stats.log, with FILE_APPEND | LOCK_EX: the lock lasts microseconds, and nothing is read.
  • hypha_getStats() adds the lines of the period to the old count in hypha.stats, and then drops the lines of periods that have been reported, so the log stays small.
Dominant language
JavaScript
Stars
5
Forks
9
Avg merge
18h 49m
Merged PRs (30d)
13

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PlanBCode/hypha

All issues in PlanBCode/hypha

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.