upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/45.md
diff options
context:
space:
mode:
Diffstat (limited to '45.md')
-rw-r--r--45.md39
1 files changed, 39 insertions, 0 deletions
diff --git a/45.md b/45.md
new file mode 100644
index 0000000..a525391
--- /dev/null
+++ b/45.md
@@ -0,0 +1,39 @@
1NIP-45
2======
3
4Event Counts
5--------------
6
7`draft` `optional` `author:staab`
8
9Relays may support the verb `COUNT`, which provides a mechanism for obtaining event counts.
10
11## Motivation
12
13Some 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
17This 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
23Counts 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
29Examples:
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```