What is Nostr?
david / David
npub1u5n…ldq3
2025-02-21 18:45:07

david on Nostr: An example of something the FOSS graph database #neo4j makes super easy: calculation ...

An example of something the FOSS graph database #neo4j makes super easy: calculation of the minimum number of hops it takes to get from a reference pubkey to any other pubkey. This can be used in a personalized grapevine WoT relay where neo4j maintains a graph of NostrUser nodes connected by FOLLOWS relationships, and the reference pubkey is YOU (you are always at the center of your grapevine!)

You only need 3 cypher commands:

MATCH (u:NostrUser) SET u.hops=999

MATCH (u:NostrUser {pubkey:'<reference pubkey>'}) SET u.hops=0

MATCH (u1:NostrUser)-[:FOLLOWS]->(u2:NostrUser) WHERE u2.hops - u1.hops > 1 SET u2.hops = u1.hops + 1

The third command repeats until no more nodes get updated, typically around 7 or 8 iterations. Each iteration typically takes well under one second.
Author Public Key
npub1u5njm6g5h5cpw4wy8xugu62e5s7f6fnysv0sj0z3a8rengt2zqhsxrldq3