Optimization of GSQL (Merge Two Queries)

Hi team can you please help me in this (How to write this in a most effective manner)
this one is taking a bit longer time, I have approx. 10 lakhs of profiles.
Below is the snippet (a part of code) which takes longer time.

This query is for Just to collect the “recent calendar” Information from the information about the customer , which I put on the edges, when My Batch job runs.
Every Profile have their own unique profile_calendar Id

 active_segment = {cv_segment.*}
latest_calendar = SELECT c from active_segment:seg-(customer_cvsegment:cvseg)-customer:c-
                (customer_calender:ccal)-profile_calendar:pc 
                ACCUM c.@latest_calender += pc.date;
  
                results = select c from latest_calendar:c-(customer_calender:ccal)-profile_calendar:pc,
                profile_calendar:pc -(calendar_visitgroup:e)- visit_group:alias_schema_3,
                profile_calendar:pc -(calendar_spendgroup:f)- spend_group:alias_schema_4
                where c.@latest_calender == pc.date ACCUM c.@average_visit_per_week += e.average_visit_per_week,
                c.@distinct_weeks_shopped += e.distinct_weeks_shopped, c.@average_weekly_spend += f.average_weekly_spend, 
                c.@average_spend_per_visit += f.average_spend_per_visit;
                PRINT results;

Thanks