Skip to content

Commit 628e2d2

Browse files
authored
Merge pull request #512 from ynput/get-used-project-tags
Helpers: get_used_project_tags helper
2 parents 2c864f2 + 590d1e7 commit 628e2d2

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

ayon_server/graphql/nodes/project.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from ayon_server.graphql.resolvers.versions import get_version, get_versions
1919
from ayon_server.graphql.resolvers.workfiles import get_workfile, get_workfiles
2020
from ayon_server.graphql.utils import parse_attrib_data
21+
from ayon_server.helpers.tags import get_used_project_tags
2122
from ayon_server.lib.postgres import Postgres
2223
from ayon_server.utils import json_dumps
2324

@@ -203,6 +204,10 @@ async def product_types(self) -> list[ProductType]:
203204
)
204205
]
205206

207+
@strawberry.field(description="List of tags used in the project")
208+
async def used_tags(self) -> list[str]:
209+
return await get_used_project_tags(self.project_name)
210+
206211

207212
def project_from_record(
208213
project_name: str | None, record: dict[str, Any], context: dict[str, Any]

ayon_server/helpers/tags.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from ayon_server.lib.postgres import Postgres
2+
3+
4+
async def get_used_project_tags(project_name: str) -> list[str]:
5+
"""Returns a list of tags that are used in the project.
6+
7+
This function is used to get all the tags that are used in the project.
8+
The tags are collected from all the entities, but don't necessarily
9+
contain tags defined in the project anatomy.
10+
"""
11+
result = []
12+
project_schema = f"project_{project_name.lower()}"
13+
query = f"""
14+
SELECT DISTINCT tag FROM (
15+
SELECT unnest(tags) AS tag FROM {project_schema}.folders
16+
UNION ALL
17+
SELECT unnest(tags) FROM {project_schema}.products
18+
UNION ALL
19+
SELECT unnest(tags) FROM {project_schema}.tasks
20+
UNION ALL
21+
SELECT unnest(tags) FROM {project_schema}.versions
22+
UNION ALL
23+
SELECT unnest(tags) FROM {project_schema}.representations
24+
UNION ALL
25+
SELECT unnest(tags) FROM {project_schema}.workfiles
26+
) t
27+
"""
28+
async for row in Postgres.iterate(query):
29+
result.append(row["tag"])
30+
return result

0 commit comments

Comments
 (0)