Browse Source

fix image description duplicate

main
ghost 2 years ago
parent
commit
2c5ca1b630
  1. 13
      crontab/crawler.php
  2. BIN
      database/yggo.mwb
  3. 12
      library/mysql.php
  4. 24
      public/search.php

13
crontab/crawler.php

@ -336,7 +336,9 @@ try { @@ -336,7 +336,9 @@ try {
if ($lastHostImageDescription = $db->getLastHostImageDescription($queueHostImage->hostImageId)) {
$db->setHostImageDescription($queueHostImage->hostImageId,
crc32($hostImageData),
crc32($lastHostImageDescription->alt .
$lastHostImageDescription->title .
$hostImageData),
$lastHostImageDescription->alt,
$lastHostImageDescription->title,
$hostImageData,
@ -618,10 +620,13 @@ try { @@ -618,10 +620,13 @@ try {
}
// Add/update host image description
$imageAlt = Filter::imageAlt($imageAlt);
$imageTitle = Filter::imageTitle($imageTitle);
$db->setHostImageDescription($hostImageId,
null, // no data, download it in the crawler queue
Filter::imageAlt($imageAlt),
Filter::imageTitle($imageTitle),
crc32($imageAlt . $imageTitle),
$imageAlt,
$imageTitle,
null,
time());

BIN
database/yggo.mwb

Binary file not shown.

12
library/mysql.php

@ -259,14 +259,14 @@ class MySQL { @@ -259,14 +259,14 @@ class MySQL {
}
public function setHostImageDescription(int $hostImageId,
mixed $crc32data,
int $crc32id,
string $alt,
string $title,
mixed $data,
int $time) {
$query = $this->_db->prepare('INSERT INTO `hostImageDescription` (`hostImageId`,
`crc32data`,
`crc32id`,
`alt`,
`title`,
`timeAdded`) VALUES (?, ?, ?, ?, ?)
@ -275,24 +275,24 @@ class MySQL { @@ -275,24 +275,24 @@ class MySQL {
`title` = ?,
`timeUpdated` = ?');
$query->execute([$hostImageId, $crc32data, $alt, $title, $time, $alt, $title, $time]);
$query->execute([$hostImageId, $crc32id, $alt, $title, $time, $alt, $title, $time]);
return $this->_db->lastInsertId();
}
public function setHostImageDescriptionData(int $hostImageId,
mixed $crc32data,
int $crc32id,
mixed $data,
int $time) {
$query = $this->_db->prepare('INSERT INTO `hostImageDescription` (`hostImageId`,
`crc32data`,
`crc32id`,
`data`,
`timeAdded`) VALUES (?, ?, ?, ?)
ON DUPLICATE KEY UPDATE `timeUpdated` = ?');
$query->execute([$hostImageId, $crc32data, $data, $time, $time]);
$query->execute([$hostImageId, $crc32id, $data, $time, $time]);
return $this->_db->lastInsertId();
}

24
public/search.php

@ -346,7 +346,7 @@ if (!empty($q)) { @@ -346,7 +346,7 @@ if (!empty($q)) {
$hostImage->uri;
// Get local image data
if ($lastHostImageDescription = $db->getLastHostImageDescription($hostImage->hostImageId)) {
if ($lastHostImageDescription = $db->getLastHostImageDescription($result->id)) {
$hostImageURLencoded = $lastHostImageDescription->data;
@ -359,13 +359,13 @@ if (!empty($q)) { @@ -359,13 +359,13 @@ if (!empty($q)) {
// Skip item render on timeout
$hostImageHttpCode = $hostImageCurl->getCode();
$db->updateHostImageHttpCode($hostImage->hostImageId, (int) $hostImageHttpCode, time());
$db->updateHostImageHttpCode($result->id, (int) $hostImageHttpCode, time());
if (200 != $hostImageHttpCode) {
$db->updateHostImageHttpCode($hostImage->hostImageId, $hostImageHttpCode, time());
$db->updateHostImageHttpCode($result->id, $hostImageHttpCode, time());
$db->updateHostImageTimeBanned($hostImage->hostImageId, time());
$db->updateHostImageTimeBanned($result->id, time());
continue;
}
@ -373,7 +373,7 @@ if (!empty($q)) { @@ -373,7 +373,7 @@ if (!empty($q)) {
// Skip image processing on MIME type not provided
if (!$hostImageContentType = $hostImageCurl->getContentType()) {
$db->updateHostImageTimeBanned($hostImage->hostImageId, time());
$db->updateHostImageTimeBanned($result->id, time());
continue;
}
@ -391,9 +391,9 @@ if (!empty($q)) { @@ -391,9 +391,9 @@ if (!empty($q)) {
if ($hostImageBanned) {
$db->updateHostImageMime($hostImage->hostImageId, $hostImageContentType, time());
$db->updateHostImageMime($result->id, $hostImageContentType, time());
$hostImagesBanned += $db->updateHostImageTimeBanned($hostImage->hostImageId, time());
$hostImagesBanned += $db->updateHostImageTimeBanned($result->id, time());
continue;
}
@ -401,7 +401,7 @@ if (!empty($q)) { @@ -401,7 +401,7 @@ if (!empty($q)) {
// Skip image processing without returned content
if (!$hostImageContent = $hostImageCurl->getContent()) {
$db->updateHostImageTimeBanned($hostImage->hostImageId, time());
$db->updateHostImageTimeBanned($result->id, time());
continue;
}
@ -409,14 +409,14 @@ if (!empty($q)) { @@ -409,14 +409,14 @@ if (!empty($q)) {
// Convert remote image data to base64 string to prevent direct URL call
if (!$hostImageExtension = @pathinfo($hostImageURL, PATHINFO_EXTENSION)) {
$db->updateHostImageTimeBanned($hostImage->hostImageId, time());
$db->updateHostImageTimeBanned($result->id, time());
continue;
}
if (!$hostImageBase64 = @base64_encode($hostImageContent)) {
$db->updateHostImageTimeBanned($hostImage->hostImageId, time());
$db->updateHostImageTimeBanned($result->id, time());
continue;
}
@ -424,11 +424,11 @@ if (!empty($q)) { @@ -424,11 +424,11 @@ if (!empty($q)) {
$hostImageURLencoded = 'data:image/' . str_replace(['svg'], ['svg+xml'], $hostImageExtension) . ';base64,' . $hostImageBase64;
// Save image content on data settings enabled
$db->updateHostImage($hostImage->hostImageId,
$db->updateHostImage($result->id,
Filter::mime($hostImageContentType),
time());
$db->setHostImageDescriptionData($hostImage->hostImageId,
$db->setHostImageDescriptionData($result->id,
crc32($hostImageURLencoded),
$hostImage->crawlMetaOnly ? null : $hostImageURLencoded,
time());

Loading…
Cancel
Save