Use ON DUPLICATE KEY update instead of checking value existence with a
separate query
This commit is contained in:
parent
9471a030d5
commit
e00dd08c23
|
@ -964,40 +964,15 @@ final class NodaWikidataFetcher {
|
|||
|
||||
// Write link to wikipedia to relevant noda DB table
|
||||
|
||||
$wikiAlreadyResult = $this->_mysqli_noda->query_by_stmt("SELECT `noda_orte`.`noda_id`
|
||||
FROM `noda_orte`
|
||||
WHERE `noda_orte`.`ort_id` = ?
|
||||
AND `noda_orte`.`noda_source` = 'Wikipedia'", "i", $placeID);
|
||||
|
||||
switch ($wikiAlreadyResult->num_rows) {
|
||||
case 0:
|
||||
|
||||
$insertWikiStmt = $this->_mysqli_noda->do_prepare("INSERT INTO `noda_orte`
|
||||
(`ort_id`, `noda_source`, `noda_nrinsource`, `noda_link`, `noda_erfasst_am`, `noda_erfasst_von`)
|
||||
VALUES
|
||||
(?, 'Wikipedia', '', ?, NOW(), ?)");
|
||||
$insertWikiStmt->bind_param("iss", $placeID, $wikilink[$lang], $erfasst_von);
|
||||
$insertWikiStmt->execute();
|
||||
$insertWikiStmt->close();
|
||||
unset($insertWikiStmt);
|
||||
|
||||
break;
|
||||
case 1:
|
||||
|
||||
if ($wikiAlreadyData = $wikiAlreadyResult->fetch_assoc()) {
|
||||
$wikischon_id = $wikiAlreadyData['noda_id'];
|
||||
|
||||
$updateStmt = $this->_mysqli_noda->do_prepare("UPDATE `noda_orte` SET `noda_link` = ? WHERE `noda_id` = ?");
|
||||
$updateStmt->bind_param("si", $wikilink[$lang], $wikischon_id);
|
||||
$updateStmt->execute();
|
||||
$updateStmt->close();
|
||||
unset($updateStmt);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$wikiAlreadyResult->close();
|
||||
unset($wikiAlreadyResult);
|
||||
$insertWikiStmt = $this->_mysqli_noda->do_prepare("INSERT INTO `noda_orte`
|
||||
(`ort_id`, `noda_source`, `noda_nrinsource`, `noda_link`, `noda_erfasst_am`, `noda_erfasst_von`)
|
||||
VALUES
|
||||
(?, 'Wikipedia', '', ?, NOW(), ?)
|
||||
ON DUPLICATE KEY UPDATE `noda_link` = ?");
|
||||
$insertWikiStmt->bind_param("isss", $placeID, $wikilink[$lang], $erfasst_von, $wikilink[$lang]);
|
||||
$insertWikiStmt->execute();
|
||||
$insertWikiStmt->close();
|
||||
unset($insertWikiStmt);
|
||||
|
||||
return true;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user