← back to Commercialrealestate
CRCP: snapLeads rank-then-slice — rank full snapshot pool by fit before taking limit (fixes Cody slice-before-rank drop of high-fit brokers)
fccb4e738ada4341aed2d6fe433ac05685bc5b5e · 2026-08-06 16:39:03 -0700 · Steve Abrams
Files touched
Diff
commit fccb4e738ada4341aed2d6fe433ac05685bc5b5e
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Thu Aug 6 16:39:03 2026 -0700
CRCP: snapLeads rank-then-slice — rank full snapshot pool by fit before taking limit (fixes Cody slice-before-rank drop of high-fit brokers)
---
scripts/serve.js | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/scripts/serve.js b/scripts/serve.js
index b4e9bae..56bb4b6 100644
--- a/scripts/serve.js
+++ b/scripts/serve.js
@@ -534,7 +534,10 @@ app.get('/api/leads/top', async (req, res) => {
if (x.includes('multi')) return 2;
if (/retail|office|industrial|commercial/.test(x)) return 2;
return 1; };
- return (s.top || []).slice(0, limit).map(t => {
+ // Rank the FULL candidate pool (snapshot top[] — capped at 50 by the export; brokers outside
+ // top-50 can't appear in the fallback), THEN take `limit` — so we don't pre-filter on the
+ // snapshot's count-order and drop a higher-fit broker (slice must come AFTER the sort).
+ return (s.top || []).map(t => {
const cur = (s.brokerDetail && s.brokerDetail[t.id] && s.brokerDetail[t.id].current) || [];
const listings_json = cur.map(p => ({ id: p.id, address: p.address, city: p.city, zip: p.zip,
type: p.type, price: p.price, units: p.units, cap_rate: p.cap_rate, created_at: p.listed_at }))
@@ -543,7 +546,7 @@ app.get('/api/leads/top', async (req, res) => {
listings: (t.listings != null ? t.listings : cur.length),
fit_score: cur.reduce((n, p) => n + fitOf(p.type), 0),
total_value: cur.reduce((n, p) => n + Number(p.price || 0), 0), listings_json };
- }).sort((a, b) => (b.fit_score - a.fit_score) || (b.total_value - a.total_value));
+ }).sort((a, b) => (b.fit_score - a.fit_score) || (b.total_value - a.total_value)).slice(0, limit);
};
if (!brokerdb) { const leads = snapLeads(); return res.json(leads ? { leads, source: 'snapshot' } : { leads: [], unavailable: true }); }
try {
← fe2521c CRCP: snapLeads() fallback for /api/leads/top — homepage bro
·
back to Commercialrealestate
·
security: npm audit fix — patch body-parser DoS (GHSA-v422-h cea4265 →