From 0e6bf8ed00abdbc82d023cfcaffc2f9d48403f7b Mon Sep 17 00:00:00 2001 From: Vesa Meskanen Date: Thu, 10 Mar 2016 09:07:22 +0200 Subject: [PATCH] Improve response deduping Consider locality and neighborhood, too. Do not take absence of an attribute as a difference. --- middleware/dedupe.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/middleware/dedupe.js b/middleware/dedupe.js index 9e0e5c6a..cd780bdf 100644 --- a/middleware/dedupe.js +++ b/middleware/dedupe.js @@ -42,13 +42,17 @@ function isDifferent(item1, item2) { if (item1.hasOwnProperty('parent') && item2.hasOwnProperty('parent')) { propMatch(item1.parent, item2.parent, 'region_a'); propMatch(item1.parent, item2.parent, 'country'); + propMatch(item1.parent, item2.parent, 'locality'); + propMatch(item1.parent, item2.parent, 'neighborhood'); } else if (item1.parent !== item2.parent) { throw new Error('different'); } if (item1.hasOwnProperty('name') && item2.hasOwnProperty('name')) { - propMatch(item1.name, item2.name, 'default'); + for (var lang in item1.name) { + propMatch(item1.name, item2.name, lang); + } } else { propMatch(item1, item2, 'name'); @@ -92,6 +96,10 @@ function propMatch(item1, item2, prop) { prop2= prop2[0]; } + if (!prop1 || !prop2) { + return; // absence of information does not make an item different + } + if (normalizeString(prop1) !== normalizeString(prop2)) { throw new Error('different'); } @@ -111,4 +119,4 @@ function normalizeString(str) { } -module.exports = setup; \ No newline at end of file +module.exports = setup;