Merge branch 'master' into hyperloglog

This commit is contained in:
fiatjaf_
2025-11-11 08:39:06 -03:00
committed by GitHub
49 changed files with 1974 additions and 770 deletions

20
45.md
View File

@@ -14,17 +14,17 @@ Some queries a client may want to execute against connected relays are prohibiti
## Filters and return values
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.
This NIP defines the verb `COUNT`, which accepts a query 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.
```
["COUNT", <subscription_id>, <filters JSON>...]
["COUNT", <query_id>, <filters JSON>...]
```
Counts are returned using a `COUNT` response in the form `{"count": <integer>}`. Relays may use probabilistic counts to reduce compute requirements.
In case a relay uses probabilistic counts, it MAY indicate it in the response with `approximate` key i.e. `{"count": <integer>, "approximate": <true|false>}`.
```
["COUNT", <subscription_id>, {"count": <integer>}]
["COUNT", <query_id>, {"count": <integer>}]
```
Whenever the relay decides to refuse to fulfill the `COUNT` request, it MUST return a `CLOSED` message.
@@ -34,7 +34,7 @@ Whenever the relay decides to refuse to fulfill the `COUNT` request, it MUST ret
Relays may return an HyperLogLog value together with the count, hex-encoded.
```
["COUNT", <subscription_id>, {"count": <integer>, "hll": "<hex>"}]
["COUNT", <query_id>, {"count": <integer>, "hll": "<hex>"}]
```
This is so it enables merging results from multiple relays and yielding a reasonable estimate of reaction counts, comment counts and follower counts, while saving many millions of bytes of bandwidth for everybody.
@@ -77,16 +77,16 @@ The value `hll` value must be the concatenation of the 256 registers, each being
### Count posts and reactions
```
["COUNT", <subscription_id>, {"kinds": [1, 7], "authors": [<pubkey>]}]
["COUNT", <subscription_id>, {"count": 5}]
["COUNT", <query_id>, {"kinds": [1, 7], "authors": [<pubkey>]}]
["COUNT", <query_id>, {"count": 5}]
```
### Count posts approximately
```
["COUNT", <subscription_id>, {"kinds": [1]}]
["COUNT", <subscription_id>, {"count": 93412452, "approximate": true}]
["COUNT", <query_id>, {"kinds": [1]}]
["COUNT", <query_id>, {"count": 93412452, "approximate": true}]
```
### Followers count with HyperLogLog
@@ -99,6 +99,6 @@ The value `hll` value must be the concatenation of the 256 registers, each being
### Relay refuses to count
```
["COUNT", <subscription_id>, {"kinds": [4], "authors": [<pubkey>], "#p": [<pubkey>]}]
["CLOSED", <subscription_id>, "auth-required: cannot count other people's DMs"]
["COUNT", <query_id>, {"kinds": [1059], "#p": [<pubkey>]}]
["CLOSED", <query_id>, "auth-required: cannot count other people's DMs"]
```