mleku on Nostr: haha, part way through making a new algorithm out of the pieces currently writing an ...
haha, part way through making a new algorithm out of the pieces
currently writing an event query function that does not fetch events unless it has to
there is two conditions it does this:
- where there is an author AND tags
- where there is tags AND kinds
for these cases, it has to grab the full events to run a query on those extra fields in the events because they don't have a second index (and i think it would be expensive to make
however, you can probably see that author/tag and tag/kind searches are probably fairly common
author/kind, doesn't need this
probably the majority of queries are this exact pattern, so it makes sense that the index is optimized towards them
anyway, it's too late at night for me to finish this algorithm, but i feel like it's going to be just a couple more pieces and done
mainly, i have created a new index that tracks the event ID, author pubkey, and the serial index key of the event in one. the majority of cases the index is already found and we know it matches, and for the other two cases, we accumulate these serials that match and then we need to search the full index, as i am calling it, and voila, we sort these found keys by the ascending/descending sort of timestamp and then extract the event Ids and return them
see, that's why i had to write this down, because i needed to explain it to myself
i need to be gathering the event serials of the matches, both the ones that match from author/kind and the ones that match from kind/tag and author/tag
and done
Published at
2025-03-23 22:32:36Event JSON
{
"id": "a1ef929f7ed42a6ace90ee826adb5b98f79f3db48c4947dd5e69bd7337beb817",
"pubkey": "4c800257a588a82849d049817c2bdaad984b25a45ad9f6dad66e47d3b47e3b2f",
"created_at": 1742769156,
"kind": 1,
"tags": [],
"content": "haha, part way through making a new algorithm out of the pieces\n\ncurrently writing an event query function that does not fetch events unless it has to\n\nthere is two conditions it does this:\n\n- where there is an author AND tags\n- where there is tags AND kinds\n\nfor these cases, it has to grab the full events to run a query on those extra fields in the events because they don't have a second index (and i think it would be expensive to make\n\nhowever, you can probably see that author/tag and tag/kind searches are probably fairly common\n\nauthor/kind, doesn't need this\n\nprobably the majority of queries are this exact pattern, so it makes sense that the index is optimized towards them\n\nanyway, it's too late at night for me to finish this algorithm, but i feel like it's going to be just a couple more pieces and done\n\nmainly, i have created a new index that tracks the event ID, author pubkey, and the serial index key of the event in one. the majority of cases the index is already found and we know it matches, and for the other two cases, we accumulate these serials that match and then we need to search the full index, as i am calling it, and voila, we sort these found keys by the ascending/descending sort of timestamp and then extract the event Ids and return them\n\nsee, that's why i had to write this down, because i needed to explain it to myself\n\ni need to be gathering the event serials of the matches, both the ones that match from author/kind and the ones that match from kind/tag and author/tag\n\nand done\n",
"sig": "feb887ad4445ce459a3d28f682408828370dd2ca45fbcc92e163cba5b6b35f57a22feda7b9304fe6edd928385cbae8f313ca251805a752f4ed32f7f08919bb50"
}