Skip to content

Bell unread count: cache the COUNT(*) per user to cut per-pageview query #118

Description

@chubes4

Context

Audit follow-up (scale paper cut, not urgent). Volume is tiny today (single-digit unread rows network-wide), so this is pre-emptive.

extrachill_users_get_unread_notification_count() (inc/notifications/bell.php) runs a COUNT(*) on the substrate table on every page load for every logged-in user, via the ability. Fine now; a needless repeated query at scale.

Proposal

Cache the per-user unread count in object cache (Redis is active) with a short TTL, busted on write:

  • read: wp_cache_get( "ec_notif_unread_{$user_id}", 'ec_notifications' ), fall back to the COUNT and set.
  • bust in ec_users_notify() (new notification) and ec_users_mark_notifications_read() / clear (count changes).

Keep the busting in the substrate (service.php) so every writer invalidates consistently.

Parent epic: Extra-Chill/extrachill-community#82.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions