Skip to content

Commit

Permalink
Add Curated Feed (#1097)
Browse files Browse the repository at this point in the history
* f

* Add scaffolding

* Fix queries

* Small refactor

* Debug pagination

* Get it to compile

* Cleanup

* Performance changes

* More QC

* Cleanup

* Remove duplicate func

* Better naming

* Scoring refactor

* Add contracts to query

* Fix tests

* Change back to trending

* Fix docstring

* More comments

* Add norec build tag (#1099)

* Add norec build tag

* Add norec to recommendation

* Rename score f

* Add relevance scale factor

* Fix local secrets

* Small change in weights

* Better docs

* More accurate description

* Merge main

* More tweaks

* Move lock out of loop

* Rename package

* Add redis

* Clean up comments

* Remove norec tag

* Remove unused type

* Add logging for sanity

* Fix time range
  • Loading branch information
jarrel-b authored Aug 2, 2023
1 parent f262a6f commit b88dc08
Show file tree
Hide file tree
Showing 18 changed files with 1,343 additions and 198 deletions.
2 changes: 1 addition & 1 deletion db/gen/coredb/batch.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 0 additions & 73 deletions db/gen/coredb/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

181 changes: 181 additions & 0 deletions db/gen/coredb/recommend.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 2 additions & 29 deletions db/queries/core/query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ ORDER BY
CASE WHEN NOT sqlc.arg('paging_forward')::bool THEN (created_at, id) END DESC
LIMIT sqlc.arg('limit');


-- name: PaginatePersonalFeedByUserID :many
select fe.* from feed_entities fe, follows fl
where fl.deleted = false
Expand Down Expand Up @@ -428,7 +427,7 @@ WHERE sqlc.arg('contract_id') = ANY(posts.contract_ids)
AND posts.deleted = false
AND (posts.created_at, posts.id) < (sqlc.arg('cur_before_time'), sqlc.arg('cur_before_id'))
AND (posts.created_at, posts.id) > (sqlc.arg('cur_after_time'), sqlc.arg('cur_after_id'))
ORDER BY
ORDER BY
CASE WHEN sqlc.arg('paging_forward')::bool THEN (posts.created_at, posts.id) END ASC,
CASE WHEN NOT sqlc.arg('paging_forward')::bool THEN (posts.created_at, posts.id) END DESC
LIMIT sqlc.arg('limit');
Expand Down Expand Up @@ -934,32 +933,6 @@ update users set user_experiences = user_experiences || @experience where id = @
-- name: GetTrendingUsersByIDs :many
select users.* from users join unnest(@user_ids::varchar[]) with ordinality t(id, pos) using (id) where deleted = false order by t.pos asc;

-- name: GetLatestFeedEntities :many
with ids as (
select id, feed_entity_type, created_at
from feed_entities fe
where fe.created_at >= @window_end
and (@include_posts::bool or feed_entity_type != @post_entity_type)
), selected_posts as (
select ids.id, ids.feed_entity_type, ids.created_at, count(distinct c.id) + count(distinct a.id) interactions
from ids
join posts p on p.id = ids.id and feed_entity_type = @post_entity_type
left join comments c on c.post_id = ids.id
left join admires a on a.post_id = ids.id
group by ids.id, ids.feed_entity_type, ids.created_at
), selected_events as (
select ids.id, ids.feed_entity_type, ids.created_at, count(distinct c.id) + count(distinct a.id) interactions
from ids
join feed_events e on e.id = ids.id and feed_entity_type = @feed_event_entity_type
left join comments c on c.feed_event_id = ids.id
left join admires a on a.feed_event_id = ids.id
where not (action = any(@excluded_feed_actions::varchar[]))
group by ids.id, ids.feed_entity_type, ids.created_at
)
select * from selected_posts
union all
select * from selected_events;

-- name: UpdateCollectionGallery :exec
update collections set gallery_id = @gallery_id, last_updated = now() where id = @id and deleted = false;

Expand Down Expand Up @@ -1485,4 +1458,4 @@ from tokens
join contracts on tokens.contract = contracts.id
join wallets on wallets.id = any(tokens.owned_by_wallets)
where tokens.id = $1 and not tokens.deleted and not contracts.deleted and not wallets.deleted
group by (tokens.token_id, contracts.address, contracts.chain, tokens.quantity) limit 1;
group by (tokens.token_id, contracts.address, contracts.chain, tokens.quantity) limit 1;
Loading

0 comments on commit b88dc08

Please sign in to comment.