From 257556f42483f3d1fe3296b4a66351c8fdfc8587 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 8 Apr 2025 23:21:25 +0000 Subject: [PATCH] Fix map endpoint including non-existent URLs in results Co-Authored-By: Nicolas Camara --- apps/api/src/__tests__/snips/map.test.ts | 19 +++++++++++++++++++ apps/api/src/controllers/v1/map.ts | 4 +++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/apps/api/src/__tests__/snips/map.test.ts b/apps/api/src/__tests__/snips/map.test.ts index 8c9ffe05..069f5417 100644 --- a/apps/api/src/__tests__/snips/map.test.ts +++ b/apps/api/src/__tests__/snips/map.test.ts @@ -31,4 +31,23 @@ describe("Map tests", () => { expect(response.body.success).toBe(true); expect(response.body.links.some(x => x.match(/^https:\/\/www\.hfea\.gov\.uk\/choose-a-clinic\/clinic-search\/results\/?\?options=\d+$/))).toBe(true); }, 60000); + + it.concurrent("does not include non-existent child URLs in parent results", async () => { + const nonExistentPath = "/non-existent-path-" + Date.now(); // Use timestamp to ensure uniqueness + const childUrl = "https://firecrawl.dev" + nonExistentPath; + + await map({ + url: childUrl, + useMock: "map-non-existent-child", + }); + + const parentResponse = await map({ + url: "https://firecrawl.dev", + useMock: "map-parent-after-child", + }); + + expect(parentResponse.statusCode).toBe(200); + expect(parentResponse.body.success).toBe(true); + expect(parentResponse.body.links.some(link => link.includes(nonExistentPath))).toBe(false); + }, 30000); }); diff --git a/apps/api/src/controllers/v1/map.ts b/apps/api/src/controllers/v1/map.ts index 49890d90..9a946c68 100644 --- a/apps/api/src/controllers/v1/map.ts +++ b/apps/api/src/controllers/v1/map.ts @@ -161,7 +161,9 @@ export async function getMapResults({ ); allResults = await Promise.all(pagePromises); - await redis.set(cacheKey, JSON.stringify(allResults), "EX", 48 * 60 * 60); // Cache for 48 hours + if (allResults.flat().filter(result => result !== null && result !== undefined).length > 0) { + await redis.set(cacheKey, JSON.stringify(allResults), "EX", 48 * 60 * 60); // Cache for 48 hours + } } // Parallelize sitemap index query with search results