diff --git a/db/queries/api/v1/leaderboard/ranked/create_view__join__efp_leaderboard.sql b/db/queries/api/v1/leaderboard/ranked/create_view__join__efp_leaderboard.sql index 7d9d04f..f912f26 100644 --- a/db/queries/api/v1/leaderboard/ranked/create_view__join__efp_leaderboard.sql +++ b/db/queries/api/v1/leaderboard/ranked/create_view__join__efp_leaderboard.sql @@ -6,9 +6,20 @@ 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, @@ -16,7 +27,8 @@ SELECT 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 diff --git a/db/schema/020__tables/001/create_table__efp_leaderboard.sql b/db/schema/020__tables/001/create_table__efp_leaderboard.sql index bf73706..6ae3a6e 100644 --- a/db/schema/020__tables/001/create_table__efp_leaderboard.sql +++ b/db/schema/020__tables/001/create_table__efp_leaderboard.sql @@ -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, diff --git a/db/schema/020__tables/001/create_table__ens_metadata.sql b/db/schema/020__tables/001/create_table__ens_metadata.sql index da40868..6029742 100644 --- a/db/schema/020__tables/001/create_table__ens_metadata.sql +++ b/db/schema/020__tables/001/create_table__ens_metadata.sql @@ -19,7 +19,7 @@ CREATE TABLE updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY ("address", "name") + PRIMARY KEY ("address") ); CREATE TRIGGER