UTXOnly / nostpy-relay

A nostr relay backed by a postgresql database, run with docker-compose
The Unlicense
17 stars 6 forks source link

Fix redis not storing search in key #57

Closed UTXOnly closed 6 months ago

UTXOnly commented 6 months ago

Fixes a bug where search key was not being stored as a redis key, due to manipulation of filters in _sanitize_event_keys() causing false positive results returned from arbitrary search filters

Example:

2024-05-11 14:09:36,949 - DEBUG - Fiters are: {'kinds': [31990], 'search': '7ab57c96fcb644c9d0d9ca0c93f40a863f7e8f6b33a4835b50ff3b3ac5c23129'}

2024-05-11 14:09:36,963 - DEBUG - Caching results , keys: {'kinds': [31990]}   value is : [[{"id": "a22aec54f45b1a33ebe2c7c545aa06aad9547f873810f933ed19d27ce489ad1f", "pubkey": "8b2ff7ceb4a1ea558bb929ce0d3513dfeca2cab712fd149551a961c822ace218", "kind": 31990, "created_at": 1706620119, "tags": [["d", "7ab57c96fcb644c9d0d9ca0c93f40a863f7e8f6b33a4835b50ff3b3ac5c23129"], ["k", "30402"], ["web", "https://shopstr.store/<bech-32>", "npub"]], "content": "", "sig": "aa0dffe7c09c0053ba1ca61c56e1955f04b75d28602120937f780e2c391e5529c1fc8bd048b4b9abe5dcc25f281a8c6740466b86f5cc5cbfcc0833a4ebe3db71"}]]

Tested with multiple queries and search filters:

12:41 52.58
[
  "EOSE",
  "somethdddisssng"
]

12:41 52.56
[
  "EVENT",
  "somethdddisssng",
  {
    "id": "a22aec54f45b1a33ebe2c7c545aa06aad9547f873810f933ed19d27ce489ad1f",
    "pubkey": "8b2ff7ceb4a1ea558bb929ce0d3513dfeca2cab712fd149551a961c822ace218",
    "kind": 31990,
    "created_at": 1706620119,
    "tags": [
      [
        "d",
        "7ab57c96fcb644c9d0d9ca0c93f40a863f7e8f6b33a4835b50ff3b3ac5c23129"
      ],
      [
        "k",
        "30402"
      ],
      [
        "web",
        "https://shopstr.store/<bech-32>",
        "npub"
      ]
    ],
    "content": "",
    "sig": "aa0dffe7c09c0053ba1ca61c56e1955f04b75d28602120937f780e2c391e5529c1fc8bd048b4b9abe5dcc25f281a8c6740466b86f5cc5cbfcc0833a4ebe3db71"
  }
]
12:41 52.39
[
  "REQ",
  "somethdddisssng",
  {
    "kinds": [
      31990
    ],
    "search": "npub"
  }
]
12:41 48.08
[
  "EOSE",
  "somethdddisssng"
]
12:41 48.00
[
  "REQ",
  "somethdddisssng",
  {
    "kinds": [
      31990
    ],
    "search": "vvfdvdfv"
  }
]
12:41 34.27
[
  "EOSE",
  "somethdddisssng"
]
12:41 34.26
[
  "EVENT",
  "somethdddisssng",
  {
    "id": "a22aec54f45b1a33ebe2c7c545aa06aad9547f873810f933ed19d27ce489ad1f",
    "pubkey": "8b2ff7ceb4a1ea558bb929ce0d3513dfeca2cab712fd149551a961c822ace218",
    "kind": 31990,
    "created_at": 1706620119,
    "tags": [
      [
        "d",
        "7ab57c96fcb644c9d0d9ca0c93f40a863f7e8f6b33a4835b50ff3b3ac5c23129"
      ],
      [
        "k",
        "30402"
      ],
      [
        "web",
        "https://shopstr.store/<bech-32>",
        "npub"
      ]
    ],
    "content": "",
    "sig": "aa0dffe7c09c0053ba1ca61c56e1955f04b75d28602120937f780e2c391e5529c1fc8bd048b4b9abe5dcc25f281a8c6740466b86f5cc5cbfcc0833a4ebe3db71"
  }
]
12:41 34.15
[
  "REQ",
  "somethdddisssng",
  {
    "kinds": [
      31990
    ],
    "search": "https://shopstr.store/<bech-32>"
  }
]
12:41 28.64
[
  "EOSE",
  "somethdddisssng"
]
12:41 28.50
[
  "REQ",
  "somethdddisssng",
  {
    "kinds": [
      31990
    ],
    "search": "30dfgdf"
  }
]
12:41 03.91
[
  "EOSE",
  "somethdddisssng"
]
12:41 03.90
[
  "EVENT",
  "somethdddisssng",
  {
    "id": "a22aec54f45b1a33ebe2c7c545aa06aad9547f873810f933ed19d27ce489ad1f",
    "pubkey": "8b2ff7ceb4a1ea558bb929ce0d3513dfeca2cab712fd149551a961c822ace218",
    "kind": 31990,
    "created_at": 1706620119,
    "tags": [
      [
        "d",
        "7ab57c96fcb644c9d0d9ca0c93f40a863f7e8f6b33a4835b50ff3b3ac5c23129"
      ],
      [
        "k",
        "30402"
      ],
      [
        "web",
        "https://shopstr.store/<bech-32>",
        "npub"
      ]
    ],
    "content": "",
    "sig": "aa0dffe7c09c0053ba1ca61c56e1955f04b75d28602120937f780e2c391e5529c1fc8bd048b4b9abe5dcc25f281a8c6740466b86f5cc5cbfcc0833a4ebe3db71"
  }
]
12:41 03.82
[
  "REQ",
  "somethdddisssng",
  {
    "kinds": [
      31990
    ],
    "search": "30402"
  }
]
12:40 49.41
[
  "EOSE",
  "somethdddisssng"
]
12:40 49.38
[
  "REQ",
  "somethdddisssng",
  {
    "kinds": [
      31990
    ],
    "search": "charity"
  }
]
12:40 43.17
[
  "EOSE",
  "somethdddisssng"
]
12:40 43.06
[
  "REQ",
  "somethdddisssng",
  {
    "kinds": [
      31990
    ],
    "search": "nasda"
  }
]
12:40 34.42
[
  "EOSE",
  "somethdddisssng"
]
12:40 34.24
[
  "REQ",
  "somethdddisssng",
  {
    "kinds": [
      31990
    ],
    "search": "non-sense"
  }
]
12:40 20.72
[
  "EOSE",
  "something"
]
12:40 20.71
[
  "EVENT",
  "something",
  {
    "id": "a22aec54f45b1a33ebe2c7c545aa06aad9547f873810f933ed19d27ce489ad1f",
    "pubkey": "8b2ff7ceb4a1ea558bb929ce0d3513dfeca2cab712fd149551a961c822ace218",
    "kind": 31990,
    "created_at": 1706620119,
    "tags": [
      [
        "d",
        "7ab57c96fcb644c9d0d9ca0c93f40a863f7e8f6b33a4835b50ff3b3ac5c23129"
      ],
      [
        "k",
        "30402"
      ],
      [
        "web",
        "https://shopstr.store/<bech-32>",
        "npub"
      ]
    ],
    "content": "",
    "sig": "aa0dffe7c09c0053ba1ca61c56e1955f04b75d28602120937f780e2c391e5529c1fc8bd048b4b9abe5dcc25f281a8c6740466b86f5cc5cbfcc0833a4ebe3db71"
  }
]
12:40 20.35
[
  "REQ",
  "something",
  {
    "kinds": [
      31990
    ],
    "search": "7ab57c96fcb644c9d0d9ca0c93f40a863f7e8f6b33a4835b50ff3b3ac5c23129"
  }
]