Damus

Recent Notes

jb55 · 93w
Well some more plugins would be nice 😅. Like duplicate content filter. I want to use token bucketing for the rate limit plugin since it’s using something pretty naive atm. We are going to be using this to implement our high push notification service since our deno one is giving us trouble
note1sed8k...
Nate Levin profile picture
Ok well that suprises me a lot. When it comes to further performance optimisations the only thing throwing a curveball is the LIMIT on some of the subqueries, otherwise this could easily become one or two queries (reducing the overall performance overhead of the UNION, which runs as an individual query, creates a temporary table, has to be sorted (in some cases), and then remerged.

An example of what I mean is

SELECT *
FROM (
SELECT *
FROM nostr_events
WHERE kind IN ($5, $6, $7)
AND pubkey IN ($8, $9)
) AS nostr_events

UNION ALL

SELECT *
FROM (
SELECT *
FROM nostr_events
WHERE kind IN ($14, $15, $16)
AND pubkey IN ($17)
) AS nostr_events

UNION ALL

SELECT *
FROM (
SELECT *
FROM nostr_events
WHERE kind IN ($21, $22, $23)
AND pubkey IN ($24, $25, $26)
) AS nostr_events;

Becomes

SELECT nostr_events.*
FROM nostr_events
WHERE
(kind IN ($5, $6, $7) AND pubkey IN ($8, $9))
OR (kind IN ($14, $15, $16) AND pubkey IN ($17))
OR (kind IN ($21, $22, $23) AND pubkey IN ($24, $25, $26))


OR

SELECT *
FROM (
SELECT *
FROM nostr_events
WHERE kind IN ($1, $2)
AND pubkey IN ($3)
LIMIT $4
) AS nostr_events

UNION ALL

SELECT *
FROM (
SELECT *
FROM nostr_events
WHERE kind IN ($5, $6, $7)
AND pubkey IN ($8, $9)
) AS nostr_events

can easily become

SELECT *
FROM nostr_events
WHERE (kind IN ($1, $2) AND pubkey IN ($3))
OR (kind IN ($5, $6, $7) AND pubkey IN ($8, $9))
LIMIT $4

if that limit is not required.

Infact all 6 of those queries could be merged into one, but it would likely return a slightly different result set due to the exclusion of LIMIT, but a lot of the other queries do not have a limit and would be easier to do than others

Please check my SQL btw, it may not return the correct result set, or it may just be straight up incorrect, it is 1.30am here.
note1gnk0s...
Nate Levin profile picture
Again, I could very well be reading this wrong, but the joins dont look necassary to me, it could look something like this

SELECT *
FROM nostr_events ne
WHERE (kind IN ($1, $2) AND pubkey IN ($3))
AND EXISTS (
SELECT 1
FROM nostr_tags tag0
WHERE tag0.event_id = ne.id
AND tag0.name = $4
AND tag0.value IN ($5, $6)
))

(this isnt directly taken from your query below, this is just an example)

This is also why i recommended the use of the composite index (event_id, name, value), which I would image would give a huge performance boost on that EXISTS check, but without being able to test it (and make sure it returns the correct results) I could be talking out of my ass
jb55 · 93w
I believe that was the original intention of the User-Agent header in browsers as well, but it ended up being abused for filtering and tracking clients
note1ll0q6...
Nate Levin profile picture
Unless Im reading this wrong (which I could very well be) the performance would likely be increased dramatically if the unions were removed, as this creates a temporary table in postgresql (or atleast it does in MYSQL which im used to) which adds a lot of overhead. I guess this is probably hard to get rid of however, as Im going to assume this is dynamically generated SQL?

Another performance optimization would be using EXISTS in a few of the queries where the INNER JOIN on nostr_tags is used just to filter (most of them)

Id also suggest if you make the EXISTS change that you create a composite index on (event_id, name, value)

This is my experience with MYSQL though, I know postgres is more efficent in some manners so maybe all of this is automatically done under the hood

If you want me to have a look further into this I would be happy to, but Id probably need to spin up a database (and therefore would need some data)
Vitor Pamplona · 94w
Relay is a relay. These gifs are small. They are not much different than the lists we already have to manage.
Brunswick · 96w
Not an argument
Brunswick · 96w
I should have predicted your politics from your last name.
calle · 97w
I said it before and I'll say it again and again: we need ideas to fix the huge traffic issue with noste. My computer starts downloading events with 20 MB/s whenever I open a new nostr tab. That's u...
Nate Levin profile picture
Youre going to have to let us know what client you are using so we can get to the bottom of this, and 20MB/s the internet speed dedicated to this activity, its not too helpful in diagnosing this, you could download 1MB @ 1000MB/s, it just would just be instant.
Brunswick · 97w
What good requires tolerance? Tolerance is to tolerate evil; be it aggression, theft, abuse, lies, or anything else. To be tolerant is to be a cowardly pushover. Stand up for your self, your wife an...
Nate Levin profile picture
I tolerate high tax rates to afford free (hospitalised) healthcare, or taking care of the sick or disabled. One could argue that is good, and one could argue it may cause stress on others. There’s one example for you of something that is good and requires tolerance, please put a little more thought into your next posts!
1
Brunswick · 97w
Tax is theft. I tolerate it because the alternative is death. I tolerate being bound and gagged while someone rifles through my house, not because this person is performing a necessary service to his children but because I have been cornered and deceived. No good comes of theft. To accept government...
Weatherall · 96w
lulzy! https://image.nostr.build/a6b28d6802204872ce311815f976751f23312a9131b82be44141534bde167c81.gif
spore · 99w
How much of your own research was thrown out in the years since covid? How many boosters did you get? Was anyone held responsible, or was everything debased with bail outs? Farming is going to become a black market if you keep believing what they're selling.