Skip to content

Commit

Permalink
feat: add dynamicity to course query
Browse files Browse the repository at this point in the history
  • Loading branch information
AfaqShuaib09 committed Sep 25, 2024
1 parent 93de0bb commit 0542ff7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 6 additions & 3 deletions course_discovery/apps/course_metadata/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 0542ff7

Please sign in to comment.