Skip to content

Commit

Permalink
ranks
Browse files Browse the repository at this point in the history
  • Loading branch information
0xthrpw committed Aug 6, 2024
1 parent a1e4f0a commit 0f4520b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,29 @@ CREATE
OR REPLACE VIEW PUBLIC.view__join__efp_leaderboard AS
SELECT
fers.address,
COALESCE(ens.name) AS ens_name,
COALESCE(ens.avatar) AS ens_avatar,
RANK () OVER (
ORDER BY mut.mutuals DESC NULLS LAST
) as mutuals_rank,
RANK () OVER (
ORDER BY fers.followers_count DESC NULLS LAST
) as followers_rank,
RANK () OVER (
ORDER BY fing.following_count DESC NULLS LAST
) as following_rank,
RANK () OVER (
ORDER BY blocks.blocks_count DESC NULLS LAST
) as blocks_rank,
COALESCE(mut.mutuals, 0 ) as mutuals,
COALESCE(fers.followers_count, 0 ) as followers,
COALESCE(fing.following_count, 0 ) as following,
COALESCE(blocks.blocks_count, 0 ) as blocks
FROM query.get_leaderboard_followers(10000) fers
LEFT OUTER JOIN query.get_leaderboard_following(10000) fing ON fing.address = fers.address
LEFT OUTER JOIN query.get_leaderboard_blocks(10000) blocks ON blocks.address = fers.address
LEFT OUTER JOIN public.view__events__efp_leaderboard_mutuals mut ON mut.leader = fers.address
LEFT OUTER JOIN public.view__events__efp_leaderboard_mutuals mut ON mut.leader = fers.address
LEFT OUTER JOIN ens_metadata ens ON ens.address::text = fers.address::text
ORDER BY mut.mutuals DESC NULLS LAST;

-- migrate:down
Expand Down
3 changes: 3 additions & 0 deletions db/schema/020__tables/001/create_table__efp_leaderboard.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ CREATE TABLE
"name" TEXT,
"avatar" TEXT,
"mutuals_rank" BIGINT,
"followers_rank" BIGINT,
"following_rank" BIGINT,
"blocks_rank" BIGINT,
"mutuals" BIGINT DEFAULT 0,
"following" BIGINT DEFAULT 0,
"followers" BIGINT DEFAULT 0,
Expand Down
2 changes: 1 addition & 1 deletion db/schema/020__tables/001/create_table__ens_metadata.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ CREATE TABLE
updated_at TIMESTAMP
WITH
TIME ZONE DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY ("address", "name")
PRIMARY KEY ("address")
);

CREATE TRIGGER
Expand Down

0 comments on commit 0f4520b

Please sign in to comment.