Skip to content

Commit

Permalink
Merge pull request #11 from aboutcircles/fix/too-many-avatar-rows-wit…
Browse files Browse the repository at this point in the history
…h-metadata

Fix/too many avatar rows with metadata
  • Loading branch information
jaensen authored Jul 18, 2024
2 parents 4c4ee5f + 41de32c commit 84972e6
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 61 deletions.
128 changes: 69 additions & 59 deletions Circles.Index.CirclesViews/DatabaseSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,67 +152,77 @@ UNION ALL
])
{
SqlMigrationItem = new SqlMigrationItem(@"
create or replace view ""V_CrcV2_Avatars"" as
with ""avatars"" as (
select ""blockNumber"",
""timestamp"",
""transactionIndex"",
""logIndex"",
""transactionHash"",
'organization' as ""type"",
null as ""invitedBy"",
""organization"" as ""avatar"",
null as ""tokenId"",
""name""
from ""CrcV2_RegisterOrganization""
union all
select ""blockNumber"",
""timestamp"",
""transactionIndex"",
""logIndex"",
""transactionHash"",
'group' as ""type"",
null as ""invitedBy"",
""group"" as ""avatar"",
""group"" as ""tokenId"",
""name""
from ""CrcV2_RegisterGroup""
union all
select ""blockNumber"",
""timestamp"",
""transactionIndex"",
""logIndex"",
""transactionHash"",
'human' as ""type"",
null as ""invitedBy"",
""avatar"",
""avatar"" as ""tokenId"",
null as ""name""
from ""CrcV2_RegisterHuman""
union all
select ""blockNumber"",
""timestamp"",
""transactionIndex"",
""logIndex"",
""transactionHash"",
'human' as ""type"",
""inviter"" as ""invitedBy"",
""invited"",
""invited"" as ""tokenId"",
null as ""name""
from ""CrcV2_InviteHuman""
create or replace view public.""V_CrcV2_Avatars""
(""blockNumber"", timestamp, ""transactionIndex"", ""logIndex"", ""transactionHash"", type, ""invitedBy"", avatar,
""tokenId"", name, ""cidV0Digest"")
as
WITH avatars AS (
SELECT ""CrcV2_RegisterOrganization"".""blockNumber"",
""CrcV2_RegisterOrganization"".""timestamp"",
""CrcV2_RegisterOrganization"".""transactionIndex"",
""CrcV2_RegisterOrganization"".""logIndex"",
""CrcV2_RegisterOrganization"".""transactionHash"",
'organization'::text AS type,
NULL::text AS ""invitedBy"",
""CrcV2_RegisterOrganization"".organization AS avatar,
NULL::text AS ""tokenId"",
""CrcV2_RegisterOrganization"".name
FROM ""CrcV2_RegisterOrganization""
UNION ALL
SELECT ""CrcV2_RegisterGroup"".""blockNumber"",
""CrcV2_RegisterGroup"".""timestamp"",
""CrcV2_RegisterGroup"".""transactionIndex"",
""CrcV2_RegisterGroup"".""logIndex"",
""CrcV2_RegisterGroup"".""transactionHash"",
'group'::text AS type,
NULL::text AS ""invitedBy"",
""CrcV2_RegisterGroup"".""group"" AS avatar,
""CrcV2_RegisterGroup"".""group"" AS ""tokenId"",
""CrcV2_RegisterGroup"".name
FROM ""CrcV2_RegisterGroup""
UNION ALL
SELECT ""CrcV2_RegisterHuman"".""blockNumber"",
""CrcV2_RegisterHuman"".""timestamp"",
""CrcV2_RegisterHuman"".""transactionIndex"",
""CrcV2_RegisterHuman"".""logIndex"",
""CrcV2_RegisterHuman"".""transactionHash"",
'human'::text AS type,
NULL::text AS ""invitedBy"",
""CrcV2_RegisterHuman"".avatar,
""CrcV2_RegisterHuman"".avatar AS ""tokenId"",
NULL::text AS name
FROM ""CrcV2_RegisterHuman""
UNION ALL
SELECT ""CrcV2_InviteHuman"".""blockNumber"",
""CrcV2_InviteHuman"".""timestamp"",
""CrcV2_InviteHuman"".""transactionIndex"",
""CrcV2_InviteHuman"".""logIndex"",
""CrcV2_InviteHuman"".""transactionHash"",
'human'::text AS type,
""CrcV2_InviteHuman"".inviter AS ""invitedBy"",
""CrcV2_InviteHuman"".invited,
""CrcV2_InviteHuman"".invited AS ""tokenId"",
NULL::text AS name
FROM ""CrcV2_InviteHuman""
)
select a.*, cid.""cidV0Digest""
from ""avatars"" a
left join (
SELECT a.""blockNumber"",
a.""timestamp"",
a.""transactionIndex"",
a.""logIndex"",
a.""transactionHash"",
a.type,
a.""invitedBy"",
a.avatar,
a.""tokenId"",
a.name,
cid.""cidV0Digest""
FROM avatars a
LEFT JOIN (
SELECT cid_1.avatar,
cid_1.""metadataDigest"" AS ""cidV0Digest"",
max(cid_1.""blockNumber"") AS ""blockNumber"",
max(cid_1.""transactionIndex"") AS ""transactionIndex"",
max(cid_1.""logIndex"") AS ""logIndex""
FROM ""CrcV2_UpdateMetadataDigest"" cid_1
GROUP BY cid_1.avatar, cid_1.""metadataDigest""
) as cid on cid.""avatar"" = a.""avatar"";
cid_1.""metadataDigest"" AS ""cidV0Digest"",
ROW_NUMBER() OVER (PARTITION BY cid_1.avatar ORDER BY cid_1.""blockNumber"" DESC, cid_1.""transactionIndex"" DESC, cid_1.""logIndex"" DESC) as rn
FROM ""CrcV2_UpdateMetadataDigest"" cid_1
) cid ON cid.avatar = a.avatar AND cid.rn = 1;
")
};

Expand Down
4 changes: 2 additions & 2 deletions Circles.Index/Circles.Index.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<Authors>Daniel Janz (Gnosis Service GmbH)</Authors>
<Copyright>Gnosis Service GmbH</Copyright>
<Product>Circles</Product>
<AssemblyVersion>1.3.7</AssemblyVersion>
<FileVersion>1.3.7</FileVersion>
<AssemblyVersion>1.3.8</AssemblyVersion>
<FileVersion>1.3.8</FileVersion>
</PropertyGroup>


Expand Down

0 comments on commit 84972e6

Please sign in to comment.