Skip to content

Add channel subscriptions, counts, creators, and DB query indexes#531

Open
king-aj-the-first wants to merge 1 commit into
Core-Foundry:mainfrom
king-aj-the-first:feat/subs
Open

Add channel subscriptions, counts, creators, and DB query indexes#531
king-aj-the-first wants to merge 1 commit into
Core-Foundry:mainfrom
king-aj-the-first:feat/subs

Conversation

@king-aj-the-first

Copy link
Copy Markdown

Summary

Adds on-chain notification channel subscriptions (creator metadata, subscriber counts, batch subscribe) and listener DB query-performance indexes.

Task 1 — Subscription Count View

  • New read-only get_subscriber_count(channel_id) on the contract
  • Count maintained on subscribe / unsubscribe (and reflected in get_channel)
  • Tests cover increment, decrement, and duplicate-subscribe leaving count unchanged

Task 2 — Batch Subscription Functionality

  • New batch_subscribe(channel_ids, subscriber) processes multiple channels in one tx
  • Structural errors (empty / >50 / paused) abort before mutation
  • Per-channel failures (missing, inactive, already subscribed) are skipped — successful subscriptions keep valid state; failures do not corrupt prior state
  • Returns BatchSubscribeResult { succeeded, failed, subscribed_ids }
  • Gas notes documented in docs/BATCH_SUBSCRIBE_GAS.md

Task 3 — Channel Creator Information

  • create_channel permanently stores the creator wallet on NotificationChannel
  • Queryable via get_channel_creator(id) and get_channel(id).creator
  • Tests verify storage and NotFound for unknown channels

Task 4 — Database Query Performance

  • Identified slow paths: scheduler claim, post-claim lock fetch, notification search, processed-event search, metrics joins, rate-limit audit
  • Added composite/partial indexes in schema.sql + migration 002-query-performance-indexes
  • Documented plans, measurement steps, and expected improvements in docs/DATABASE_QUERY_PERFORMANCE.md
  • Added query-performance.test.ts to assert indexes exist and claim queries use an indexed plan

New contract APIs

Function Purpose
create_channel Create channel + store creator
get_channel Full metadata
get_channel_creator Creator address
get_subscriber_count Active subscriber count
is_channel_subscriber Membership check
subscribe / unsubscribe Single-channel ops
batch_subscribe Multi-channel subscribe

Test plan

  • Contract: channel_subscription_test (creator, count, batch + partial failure)
  • Listener: query-performance.test.ts
  • Review docs/BATCH_SUBSCRIBE_GAS.md and docs/DATABASE_QUERY_PERFORMANCE.md
  • Apply migration 002 on an existing listener DB and confirm indexes via PRAGMA index_list

closes #471
closes #478
closes #480
closes #486

@drips-wave

drips-wave Bot commented Jul 26, 2026

Copy link
Copy Markdown

@king-aj-the-first Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve Database Query Performance Add Channel Creator Information Add Subscription Count View Add Batch Subscription Functionality

1 participant