Skip to content

Commit

Permalink
fix: don't show duplicate maintainers
Browse files Browse the repository at this point in the history
  • Loading branch information
ewan-escience committed Aug 7, 2024
1 parent e5a8cfc commit 56a652b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 52 deletions.
55 changes: 29 additions & 26 deletions database/008-community.sql
Original file line number Diff line number Diff line change
Expand Up @@ -206,40 +206,43 @@ BEGIN
END IF;

RETURN QUERY
-- primary maintainer of community
SELECT
community.primary_maintainer AS maintainer,
ARRAY_AGG(login_for_account."name") AS name,
ARRAY_AGG(login_for_account.email) AS email,
ARRAY_AGG(login_for_account.home_organisation) AS affiliation,
TRUE AS is_primary
FROM
community
INNER JOIN
login_for_account ON community.primary_maintainer = login_for_account.account
WHERE
community.id = community_id
GROUP BY
community.id,community.primary_maintainer
-- append second selection
UNION
-- other maintainers of community
WITH maintainer_ids AS (
-- primary maintainer of community
SELECT
community.primary_maintainer AS maintainer,
TRUE AS is_primary
FROM
community
WHERE
community.id = community_id
-- append second selection
UNION ALL
-- other maintainers of community
SELECT
maintainer_for_community.maintainer,
FALSE AS is_primary
FROM
maintainer_for_community
WHERE
maintainer_for_community.community = community_id
-- primary as first record
ORDER BY is_primary DESC
)
SELECT
maintainer_for_community.maintainer,
maintainer_ids.maintainer AS maintainer,
ARRAY_AGG(login_for_account."name") AS name,
ARRAY_AGG(login_for_account.email) AS email,
ARRAY_AGG(login_for_account.home_organisation) AS affiliation,
FALSE AS is_primary
BOOL_OR(maintainer_ids.is_primary) AS is_primary
FROM
maintainer_for_community
maintainer_ids
INNER JOIN
login_for_account ON maintainer_for_community.maintainer = login_for_account.account
WHERE
maintainer_for_community.community = community_id
login_for_account ON login_for_account.account = maintainer_ids.maintainer
GROUP BY
maintainer_for_community.community, maintainer_for_community.maintainer
maintainer_ids.maintainer
-- primary as first record
ORDER BY is_primary DESC;
ORDER BY
is_primary DESC;
RETURN;
END
$$;
Expand Down
53 changes: 27 additions & 26 deletions database/100-create-api-views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -707,40 +707,41 @@ BEGIN
END IF;

RETURN QUERY
-- primary maintainer of organisation
SELECT
organisation.primary_maintainer AS maintainer,
ARRAY_AGG(login_for_account."name") AS name,
ARRAY_AGG(login_for_account.email) AS email,
ARRAY_AGG(login_for_account.home_organisation) AS affiliation,
TRUE AS is_primary
FROM
organisation
INNER JOIN
login_for_account ON organisation.primary_maintainer = login_for_account.account
WHERE
organisation.id = organisation_id
GROUP BY
organisation.id,organisation.primary_maintainer
-- append second selection
UNION
-- other maintainers of organisation
WITH maintainer_ids AS (
-- primary maintainer of organisation
SELECT
organisation.primary_maintainer AS maintainer,
TRUE AS is_primary
FROM
organisation
WHERE
organisation.id = organisation_id
-- append second selection
UNION ALL
-- other maintainers of organisation
SELECT
maintainer_for_organisation.maintainer AS maintainer,
FALSE AS is_primary
FROM
maintainer_for_organisation
WHERE
maintainer_for_organisation.organisation = organisation_id
)
SELECT
maintainer_for_organisation.maintainer,
maintainer_ids.maintainer AS maintainer,
ARRAY_AGG(login_for_account."name") AS name,
ARRAY_AGG(login_for_account.email) AS email,
ARRAY_AGG(login_for_account.home_organisation) AS affiliation,
FALSE AS is_primary
BOOL_OR(maintainer_ids.is_primary) AS is_primary
FROM
maintainer_for_organisation
maintainer_ids
INNER JOIN
login_for_account ON maintainer_for_organisation.maintainer = login_for_account.account
WHERE
maintainer_for_organisation.organisation = organisation_id
login_for_account ON login_for_account.account = maintainer_ids.maintainer
GROUP BY
maintainer_for_organisation.organisation, maintainer_for_organisation.maintainer
maintainer_ids.maintainer
-- primary as first record
ORDER BY is_primary DESC;
ORDER BY
is_primary DESC;
RETURN;
END
$$;
Expand Down

0 comments on commit 56a652b

Please sign in to comment.