Compare commits

...

2 Commits

Author SHA1 Message Date
Leo Wandersleb
d5906545f8 some clarification 2023-05-06 12:34:30 -04:00
Leo Wandersleb
535cfcc7e5 Document multiple queries in a COUNT request 2023-05-06 12:29:09 -04:00

12
45.md
View File

@@ -6,21 +6,21 @@ Event Counts
`draft` `optional` `author:staab` `draft` `optional` `author:staab`
Relays may support the `COUNT` verb, which provides a mechanism for obtaining event counts. Relays may support the verb `COUNT`, which provides a mechanism for obtaining event counts.
## Motivation ## Motivation
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 and 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. 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.
## Filters and return values ## Filters and return values
This NIP defines a verb called `COUNT`, which accepts a subscription id and filters as specified in [NIP 01](01.md). This NIP defines the verb `COUNT`, which accepts a subscription id and filters as specified in [NIP 01](01.md) for the verb `REQ`.
``` ```
["COUNT", <subscription_id>, <filters JSON>...] ["COUNT", <subscription_id>, <filters JSON>...]
``` ```
Counts are returned using a `COUNT` response in the form `{count: <integer>}`. Relays may use probabilistic counts to reduce compute requirements. Counts are returned using a `COUNT` response with positional "count" objects in the form `{"count": <integer>}`. Relays may use probabilistic counts to reduce compute requirements.
``` ```
["COUNT", <subscription_id>, {"count": <integer>}] ["COUNT", <subscription_id>, {"count": <integer>}]
@@ -36,4 +36,8 @@ Examples:
# Count posts and reactions # Count posts and reactions
["COUNT", <subscription_id>, {"kinds": [1, 7], "authors": [<pubkey>]}] ["COUNT", <subscription_id>, {"kinds": [1, 7], "authors": [<pubkey>]}]
["COUNT", <subscription_id>, {"count": 5}] ["COUNT", <subscription_id>, {"count": 5}]
# Both of the above in one `COUNT`
["COUNT", <subscription_id>, {"kinds": [3], "#p": [<pubkey>]}, {"kinds": [1, 7], "authors": [<pubkey>]}]
["COUNT", <subscription_id>, {"count": 238}, {"count": 5}]
``` ```