From 0542ff7743fca1b5e0de634259fd8ed49261e146 Mon Sep 17 00:00:00 2001 From: Muhammad Afaq Shuaib Date: Wed, 25 Sep 2024 18:57:13 +0500 Subject: [PATCH] feat: add dynamicity to course query --- course_discovery/apps/course_metadata/constants.py | 9 ++++++--- .../management/commands/populate_product_catalog.py | 8 +++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/course_discovery/apps/course_metadata/constants.py b/course_discovery/apps/course_metadata/constants.py index ed39c57094..4d709c47a2 100644 --- a/course_discovery/apps/course_metadata/constants.py +++ b/course_discovery/apps/course_metadata/constants.py @@ -166,6 +166,7 @@ class PathwayType(Enum): cr.key as COURSERUN_KEY, c.title AS COURSE_TITLE, coursetype.name AS COURSE_TYPE, + product_source.slug AS PRODUCT_SOURCE, COUNT(DISTINCT org.id) AS ORGANIZATIONS_COUNT, LISTAGG(DISTINCT org.key, ', ') AS ORGANISATION_ABBR, LISTAGG(DISTINCT org.name, ', ') AS ORGANIZATION_NAME, @@ -232,13 +233,15 @@ class PathwayType(Enum): JOIN discovery.course_metadata_subjecttranslation AS st ON st.master_id = sb.id JOIN - discovery.course_metadata_courseurlslug AS cslug ON c.id = cslug.course_id + discovery.course_metadata_courseurlslug AS cslug ON c.id = cslug.course_id + JOIN + discovery.course_metadata_source as PRODUCT_SOURCE on c.product_source_id = PRODUCT_SOURCE.id WHERE c.draft != 1 AND cr.hidden != 1 AND cr.status = 'published' AND coursetype.slug IN ( {course_types} ) - AND cslug.is_active = 1 + AND cslug.is_active = 1 {product_source_filter} GROUP BY - c.uuid, c.id, c.key, cr.key, c.title, coursetype.name, p.marketing_site_url_root, cslug.url_Slug, c.image, c.card_image_url, cr.RUN_START, cr.enrollment_end, cr.enrollment_start, cr.RUN_END, crt.is_marketable, cr.draft, cr.status, s.id, cr.slug + c.uuid, c.id, c.key, cr.key, c.title, coursetype.name, p.marketing_site_url_root, cslug.url_Slug, c.image, c.card_image_url, cr.RUN_START, cr.enrollment_end, cr.enrollment_start, cr.RUN_END, crt.is_marketable, cr.draft, cr.status, s.id, cr.slug, product_source.slug ORDER BY c.id ) diff --git a/course_discovery/apps/course_metadata/management/commands/populate_product_catalog.py b/course_discovery/apps/course_metadata/management/commands/populate_product_catalog.py index edb7099fec..89a47684a1 100644 --- a/course_discovery/apps/course_metadata/management/commands/populate_product_catalog.py +++ b/course_discovery/apps/course_metadata/management/commands/populate_product_catalog.py @@ -87,9 +87,15 @@ def get_products_via_snowflake(self, product_type='ocm_course', product_source=N ) cs = snowflake_client.cursor() course_types = ', '.join([f"'{ct}'" for ct in COURSE_TYPES.get(product_type, [])]) + product_source_filter = f"AND product_source.slug='{product_source}'" if product_source else '' rows = [] try: - cs.execute(SNOWFLAKE_POPULATE_PRODUCT_CATALOG_QUERY.format(course_types=course_types)) + cs.execute( + SNOWFLAKE_POPULATE_PRODUCT_CATALOG_QUERY.format( + course_types=course_types, + product_source_filter=product_source_filter + ) + ) rows = cs.fetchall() except Exception as e: logger.error('Error while fetching products from Snowflake for product catalog: %s', str(e))