What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Is there a quick way to mark all categories with 0 products as inactive?

U03T08LE3CP
U03T08LE3CP Posts: 185 πŸ§‘πŸ»β€πŸš€ - Cadet

Is there a quick way to mark all categories with 0 products as inactive?

Comments

  • U03T08LE3CP
    U03T08LE3CP Posts: 185 πŸ§‘πŸ»β€πŸš€ - Cadet

    (other than querying and setting so from SQL)

  • U04FXCTCWPP
    U04FXCTCWPP Posts: 91 πŸ§‘πŸ»β€πŸš€ - Cadet

    Not to my knowledge. The SQL way you've mentioned does seem to be the simplest, quickest solution to me too.

  • U03T08LE3CP
    U03T08LE3CP Posts: 185 πŸ§‘πŸ»β€πŸš€ - Cadet

    it gets kinda tricky to get only leaf nodes but doable, lets see

  • U03T08LE3CP
    U03T08LE3CP Posts: 185 πŸ§‘πŸ»β€πŸš€ - Cadet
    update spy_category set is_active = 0 where spy_category.id_category not in (
    with recursive tree (id_category, category_key, fk_parent_category_node, is_active) as (
        select id_category, category_key, fk_parent_category_node, is_active from spy_category sp
        left join spy_product_category spc on sp.id_category = spc.fk_category
        left join spy_category_node ndc on sp.id_category = ndc.fk_category
        where spc.fk_category is not NULL
        and ndc.fk_parent_category_node is not null
        UNION ALL
        select p.id_category, p.category_key, ndc.fk_parent_category_node, p.is_active from spy_category p
        left join spy_product_category spc on p.id_category = spc.fk_category
        left join spy_category_node ndc on p.id_category = ndc.fk_category
        inner join tree on p.id_category = tree.fk_parent_category_node
    )
    select distinct (id_category) from tree order by category_key);
    
  • U03T08LE3CP
    U03T08LE3CP Posts: 185 πŸ§‘πŸ»β€πŸš€ - Cadet

    Maybe.

  • U04FXCTCWPP
    U04FXCTCWPP Posts: 91 πŸ§‘πŸ»β€πŸš€ - Cadet

    Looks good πŸ‘

  • U03T08LE3CP
    U03T08LE3CP Posts: 185 πŸ§‘πŸ»β€πŸš€ - Cadet

    docker/sdk console publish:trigger-events -r category_node

  • U03T08LE3CP
    U03T08LE3CP Posts: 185 πŸ§‘πŸ»β€πŸš€ - Cadet

    is this the command to update search? Seems to take forever

  • U04FXCTCWPP
    U04FXCTCWPP Posts: 91 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited December 2022

    Based on the description, looks like that to me.
    (Although previously, we used console event:trigger -r [resource name] for such updates, and that was pretty fast (if it only had small amounts of data to work with.)

  • U04FXCTCWPP
    U04FXCTCWPP Posts: 91 πŸ§‘πŸ»β€πŸš€ - Cadet

    (You should also be able to use -i [comma separated id list] to specify ids you'd like to update and then it can be even faster as then it won't need to bother with the rest, just with the ones you specified).