diff --git a/sql/lbryexplorer.ddl.sql b/sql/lbryexplorer.ddl.sql index 8b9b3fa..53f6ab4 100644 --- a/sql/lbryexplorer.ddl.sql +++ b/sql/lbryexplorer.ddl.sql @@ -201,6 +201,7 @@ CREATE TABLE `Claims` PRIMARY KEY `PK_Claim` (`Id`), FOREIGN KEY `FK_ClaimTransaction` (`TransactionHash`) REFERENCES `Transactions` (`Hash`), FOREIGN KEY `FK_ClaimPublisher` (`PublisherId`) REFERENCES `Claims` (`ClaimId`), + UNIQUE KEY `Idx_ClaimUnique` (`TransactionHash`, `Vout`, `ClaimId`), CONSTRAINT `Cnt_ClaimCertificate` CHECK(`Certificate` IS NULL OR JSON_VALID(`Certificate`)), -- certificate type INDEX `Idx_Claim` (`ClaimId`), INDEX `Idx_ClaimTransactionTime` (`TransactionTime`), @@ -230,3 +231,5 @@ CREATE TABLE `PriceHistory` PRIMARY KEY `PK_PriceHistory` (`Id`), UNIQUE KEY `Idx_PriceHistoryCreated` (`Created`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4; + +ALTER TABLE Claims ADD UNIQUE KEY `Idx_ClaimUnique` (`TransactionHash`, `Vout`, `ClaimId`); \ No newline at end of file diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index 6c8e90e..2be899c 100644 --- a/src/Controller/MainController.php +++ b/src/Controller/MainController.php @@ -100,7 +100,9 @@ class MainController extends AppController { // recent claims $claims = $this->Claims->find()->select(['TransactionHash', 'Name', 'Vout', 'ClaimId', 'ClaimType', 'Author', 'Title', 'Description', 'ContentType', - 'IsNSFW', 'Language', 'ThumbnailUrl', 'Created'])->contain(['Publisher' => ['fields' => ['Name']]])->order(['Claims.Created' => 'DESC'])->limit(5)->toArray(); + 'IsNSFW', 'Language', 'ThumbnailUrl', 'Created'])-> + distinct(['Claims.ClaimId'])-> + contain(['Publisher' => ['fields' => ['Name']]])->order(['Claims.Created' => 'DESC'])->limit(5)->toArray(); $this->set('recentBlocks', $blocks); $this->set('recentClaims', $claims); @@ -137,7 +139,7 @@ class MainController extends AppController { } $offset = ($page - 1) * $pageLimit; - $claims = $this->Claims->find()->contain(['Stream', 'Publisher' => ['fields' => ['Name']]])->order(['Claims.Created' => 'DESC'])->offset($offset)->limit($pageLimit)->toArray(); + $claims = $this->Claims->find()->distinct(['Claims.ClaimId'])->contain(['Stream', 'Publisher' => ['fields' => ['Name']]])->order(['Claims.Created' => 'DESC'])->offset($offset)->limit($pageLimit)->toArray(); for ($i = 0; $i < count($claims); $i++) { if ($canConvert && $claims[$i]->Fee > 0 && $claims[$i]->FeeCurrency == 'USD') { $claims[$i]->Price = $claims[$i]->Fee / $priceInfo->price;