private static function doSmartUpdate($coords, $pageId) { $prevCoords = GeoData::getAllCoordinates($pageId, array(), DB_MASTER); $add = array(); $delete = array(); foreach ($prevCoords as $old) { $delete[$old->id] = $old; } foreach ($coords as $new) { $match = false; foreach ($delete as $id => $old) { if ($new->fullyEqualsTo($old)) { unset($delete[$id]); $match = true; break; } } if (!$match) { $add[] = $new->getRow($pageId); } } $dbw = wfGetDB(DB_MASTER); if (count($delete)) { $dbw->delete('geo_tags', array('gt_id' => array_keys($delete)), __METHOD__); } if (count($add)) { $dbw->insert('geo_tags', $add, __METHOD__); } }