diff options
| author | Jon Staab <jstaab@protonmail.com> | 2023-05-12 05:10:45 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-12 05:10:45 -0700 |
| commit | e5302f84c74cf42d878a3ed18257a16bc0d3b748 (patch) | |
| tree | b1a3ad9c0317bf7c38f34c500559b66ff7c0a22d /45.md | |
| parent | 1c728516dfdc7508ce27eda222bde78466e3457d (diff) | |
| parent | 4208652dc7a39c63c39559b13c656ec30400fcba (diff) | |
Merge branch 'master' into patch-1
Diffstat (limited to '45.md')
| -rw-r--r-- | 45.md | 39 |
1 files changed, 39 insertions, 0 deletions
| @@ -0,0 +1,39 @@ | |||
| 1 | NIP-45 | ||
| 2 | ====== | ||
| 3 | |||
| 4 | Event Counts | ||
| 5 | -------------- | ||
| 6 | |||
| 7 | `draft` `optional` `author:staab` | ||
| 8 | |||
| 9 | Relays may support the verb `COUNT`, which provides a mechanism for obtaining event counts. | ||
| 10 | |||
| 11 | ## Motivation | ||
| 12 | |||
| 13 | Some queries a client may want to execute against connected relays are prohibitively expensive, for example, in order to retrieve follower counts for a given pubkey, a client must query all kind-3 events referring to a given pubkey only to count them. The result may be cached, either by a client or by a separate indexing server as an alternative, but both options erode the decentralization of the network by creating a second-layer protocol on top of Nostr. | ||
| 14 | |||
| 15 | ## Filters and return values | ||
| 16 | |||
| 17 | This NIP defines the verb `COUNT`, which accepts a subscription id and filters as specified in [NIP 01](01.md) for the verb `REQ`. Multiple filters are OR'd together and aggregated into a single count result. | ||
| 18 | |||
| 19 | ``` | ||
| 20 | ["COUNT", <subscription_id>, <filters JSON>...] | ||
| 21 | ``` | ||
| 22 | |||
| 23 | Counts are returned using a `COUNT` response in the form `{"count": <integer>}`. Relays may use probabilistic counts to reduce compute requirements. | ||
| 24 | |||
| 25 | ``` | ||
| 26 | ["COUNT", <subscription_id>, {"count": <integer>}] | ||
| 27 | ``` | ||
| 28 | |||
| 29 | Examples: | ||
| 30 | |||
| 31 | ``` | ||
| 32 | # Followers count | ||
| 33 | ["COUNT", <subscription_id>, {"kinds": [3], "#p": [<pubkey>]}] | ||
| 34 | ["COUNT", <subscription_id>, {"count": 238}] | ||
| 35 | |||
| 36 | # Count posts and reactions | ||
| 37 | ["COUNT", <subscription_id>, {"kinds": [1, 7], "authors": [<pubkey>]}] | ||
| 38 | ["COUNT", <subscription_id>, {"count": 5}] | ||
| 39 | ``` | ||