Wrong number of clan members

Hello I have a strange problem In the Nakama panel I see the number of members of a clan as 97, but when I look at the member list it is 102! I saw this by chance and maybe in other cases this difference is even greater! What is the solution?

Hi @rhs3322,

What version of Nakama are you running? Make sure you upgrade, this is likely due to a bug that has since been fixed.

You can check if there’s a discrepancy with the following raw query:

WITH c AS (
   SELECT destination_id AS group_id, count(*) FROM group_edge AS ge WHERE ge.state NOT IN (3,4) GROUP BY ge.destination_id
)
SELECT g.id AS group_id, coalesce(c.count, 0) AS actual_count, g.edge_count FROM groups AS g LEFT JOIN c ON g.id = c.group_id WHERE g.edge_count != c.count OR c.group_id IS NULL;

And you should be able to fix it by running the following:

UPDATE groups AS g SET edge_count = ec.actual_count FROM 
(
   WITH c AS (
      SELECT destination_id AS group_id, count(*) FROM group_edge AS ge WHERE ge.state NOT IN (3,4) GROUP BY ge.destination_id
   )
   SELECT g.id AS group_id, coalesce(c.count, 0) AS actual_count, g.edge_count FROM groups AS g LEFT JOIN c ON g.id = c.group_id WHERE g.edge_count != c.count OR c.group_id IS NULL
) AS ec
WHERE 
   g.id = ec.group_id;

I am using version nakama-3.25.0-linux-amd64.tar