From c4ff816178bb103abb32936804f10063b09c0585 Mon Sep 17 00:00:00 2001 From: daniel <4954577+jaensen@users.noreply.github.com> Date: Tue, 24 Sep 2024 23:54:14 +0200 Subject: [PATCH] add the V_Crc_Stats view --- Circles.Index.CirclesViews/DatabaseSchema.cs | 84 +++++++++++++++++++- 1 file changed, 82 insertions(+), 2 deletions(-) diff --git a/Circles.Index.CirclesViews/DatabaseSchema.cs b/Circles.Index.CirclesViews/DatabaseSchema.cs index 8c74058..3134a16 100644 --- a/Circles.Index.CirclesViews/DatabaseSchema.cs +++ b/Circles.Index.CirclesViews/DatabaseSchema.cs @@ -699,7 +699,7 @@ select account new("tokenOwner", ValueTypes.String, true) ]) { - SqlMigrationItem = new (@" + SqlMigrationItem = new(@" create or replace view ""V_Crc_Tokens"" as select ""blockNumber"", @@ -737,7 +737,83 @@ union all ""avatar"" as ""tokenOwner"" from ""CrcV2_ERC20WrapperDeployed"" where ""circlesType"" = 0; - ") + ") + }; + + public static readonly EventSchema V_Crc_Stats = new("V_Crc", "Stats", new byte[32], [ + new("measure", ValueTypes.String, false), + new("value", ValueTypes.Int, false) + ]) + { + SqlMigrationItem = new(@" + create or replace view ""V_Crc_Stats""(""measure"", ""value"") + as + select 'avatar_count_v1' as measure, count(""user"") as value + from ""V_CrcV1_Avatars"" + union all + select 'organization_count_v1' as measure, count(""user"") as value + from ""V_CrcV1_Avatars"" + where token is null + union all + select 'human_count_v1' as measure, count(""user"") as value + from ""V_CrcV1_Avatars"" + where token is not null + union all + select 'avatar_count_v2', count(""avatar"") + from ""V_CrcV2_Avatars"" + union all + select 'organization_count_v2', count(organization) + from ""CrcV2_RegisterOrganization"" + union all + select 'human_count_v2', count(avatar) + from ""CrcV2_RegisterHuman"" + union all + select 'group_count_v2', count(""group"") + from ""CrcV2_RegisterGroup"" + union all + select 'trust_count_v1', + (SELECT COUNT(*) + FROM (SELECT DISTINCT ON (""user"", ""canSendTo"") ""user"", ""canSendTo"", ""limit"" + FROM ""CrcV1_Trust"" + ORDER BY ""user"", ""canSendTo"", ""blockNumber"" DESC, ""transactionIndex"" DESC, ""logIndex"" DESC) t + WHERE ""limit"" > 0) + union all + select 'trust_count_v2', count(*) + from ""V_CrcV2_TrustRelations"" + union all + select 'group_count_v2', count(*) + from ""V_CrcV2_Groups"" + union all + select 'token_count_v1', count(*) + from ""V_Crc_Tokens"" + where version = 1 + union all + select 'token_count_v2', count(*) + from ""V_Crc_Tokens"" + where version = 2 + union all + select 'transitive_transfer_count_v1', count(*) + from ""CrcV1_HubTransfer"" + union all + select 'transitive_transfer_count_v2', count(*) + from ""CrcV2_StreamCompleted"" + union all + select 'circles_transfer_count_v1', count(*) + from ""CrcV1_Transfer"" + union all + select 'circles_transfer_count_v2', ( + select sum(t.value) from ( + select count(*) as value + from ""CrcV2_TransferSingle"" + union all + select count(*) + from ""CrcV2_TransferBatch"" + ) as t + ) + union all + select 'erc20_wrapper_token_count_v2', count(*) + from ""CrcV2_ERC20WrapperDeployed""; + ") }; public IDictionary<(string Namespace, string Table), EventSchema> Tables { get; } = @@ -794,6 +870,10 @@ union all { ("V_CrcV2", "BalancesByAccountAndToken"), V_CrcV2_BalancesByAccountAndToken + }, + { + ("V_Crc", "Stats"), + V_Crc_Stats } }; } \ No newline at end of file