db/events: ensure the latest author is used

This commit is contained in:
Alex Gleason 2023-12-11 13:46:38 -06:00
parent e91fbf7b50
commit 4d655c904b
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -157,11 +157,17 @@ function getFilterQuery(filter: DittoFilter): EventQuery {
eb
.selectFrom('events')
.selectAll()
.select([
eb.fn.agg('row_number')
.over((ob) => ob.partitionBy('pubkey').orderBy('created_at', 'desc'))
.as('rn'),
])
.where('kind', '=', 0)
.orderBy('created_at', 'desc')
.groupBy('pubkey')
.as('authors'),
(join) => join.onRef('authors.pubkey', '=', 'events.pubkey'),
(join) =>
join
.onRef('authors.pubkey', '=', 'events.pubkey')
.on('authors.rn', '=', 1),
)
.select([
'authors.id as author_id',