From be190a4435fc8ff4548c7fc8896a828753703b45 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 5 May 2025 16:18:33 -0400 Subject: [PATCH 1/3] fix workflow sorting by last run/crawl time fields to show new first handle null `lastRun` values in lastRun, lastCrawlTime, and lastCrawlStartTime sorts - add temporary `lastRunHelper` field to sort unrun workflows first - sort by crawl running status, helper field, then target field - remove helper field after sorting completes --- backend/btrixcloud/crawlconfigs.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/backend/btrixcloud/crawlconfigs.py b/backend/btrixcloud/crawlconfigs.py index 1b1e236589..04597cf820 100644 --- a/backend/btrixcloud/crawlconfigs.py +++ b/backend/btrixcloud/crawlconfigs.py @@ -608,12 +608,30 @@ async def get_crawl_configs( if sort_by == "name": sort_query["firstSeed"] = sort_direction - # modified for last* fields in case crawl hasn't been run yet + # Special case for last-* fields in case crawl is running or hasn't been run yet elif sort_by in ("lastRun", "lastCrawlTime", "lastCrawlStartTime"): - sort_query["modified"] = sort_direction + # Add helper to sort null values first (i.e. when a workflow hasn't been run yet) + aggregate.extend([{ + "$addFields": { + "lastRunHelper": { + "$cond": {"if": {"$eq": ["$lastRun", None]}, "then": 1, "else": 0} + } + } + }]) + sort_query = { + "isCrawlRunning": sort_direction, + "lastRunHelper": sort_direction, + sort_by: sort_direction, + "modified": sort_direction + } aggregate.extend([{"$sort": sort_query}]) + if sort_by in ("lastRun", "lastCrawlTime", "lastCrawlStartTime"): + # Remove helpers added earlier + aggregate.extend([{"$unset": "lastRunHelper"}]) + + aggregate.extend( [ { From 12a036ae76076ba200cefe06b209256b34841ba9 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 5 May 2025 16:28:21 -0400 Subject: [PATCH 2/3] format --- backend/btrixcloud/crawlconfigs.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/backend/btrixcloud/crawlconfigs.py b/backend/btrixcloud/crawlconfigs.py index 04597cf820..6698e8f4eb 100644 --- a/backend/btrixcloud/crawlconfigs.py +++ b/backend/btrixcloud/crawlconfigs.py @@ -611,18 +611,26 @@ async def get_crawl_configs( # Special case for last-* fields in case crawl is running or hasn't been run yet elif sort_by in ("lastRun", "lastCrawlTime", "lastCrawlStartTime"): # Add helper to sort null values first (i.e. when a workflow hasn't been run yet) - aggregate.extend([{ - "$addFields": { - "lastRunHelper": { - "$cond": {"if": {"$eq": ["$lastRun", None]}, "then": 1, "else": 0} + aggregate.extend( + [ + { + "$addFields": { + "lastRunHelper": { + "$cond": { + "if": {"$eq": ["$lastRun", None]}, + "then": 1, + "else": 0, + } + } + } } - } - }]) + ] + ) sort_query = { "isCrawlRunning": sort_direction, "lastRunHelper": sort_direction, sort_by: sort_direction, - "modified": sort_direction + "modified": sort_direction, } aggregate.extend([{"$sort": sort_query}]) @@ -631,7 +639,6 @@ async def get_crawl_configs( # Remove helpers added earlier aggregate.extend([{"$unset": "lastRunHelper"}]) - aggregate.extend( [ { From 4a9fd6101f9ee7322fe33669f6a11e2c918f722c Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 7 May 2025 13:55:17 -0400 Subject: [PATCH 3/3] remove parts of sorting logic that push not-yet-run workflows to the top --- backend/btrixcloud/crawlconfigs.py | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/backend/btrixcloud/crawlconfigs.py b/backend/btrixcloud/crawlconfigs.py index 6698e8f4eb..c0ab98f6ce 100644 --- a/backend/btrixcloud/crawlconfigs.py +++ b/backend/btrixcloud/crawlconfigs.py @@ -608,37 +608,16 @@ async def get_crawl_configs( if sort_by == "name": sort_query["firstSeed"] = sort_direction - # Special case for last-* fields in case crawl is running or hasn't been run yet + # Special case for last-* fields in case crawl is running elif sort_by in ("lastRun", "lastCrawlTime", "lastCrawlStartTime"): - # Add helper to sort null values first (i.e. when a workflow hasn't been run yet) - aggregate.extend( - [ - { - "$addFields": { - "lastRunHelper": { - "$cond": { - "if": {"$eq": ["$lastRun", None]}, - "then": 1, - "else": 0, - } - } - } - } - ] - ) sort_query = { "isCrawlRunning": sort_direction, - "lastRunHelper": sort_direction, sort_by: sort_direction, "modified": sort_direction, } aggregate.extend([{"$sort": sort_query}]) - if sort_by in ("lastRun", "lastCrawlTime", "lastCrawlStartTime"): - # Remove helpers added earlier - aggregate.extend([{"$unset": "lastRunHelper"}]) - aggregate.extend( [ {