added distinct selector for ClaimId when selecting claims to prevent duplicates (due to joins which should be fixed) from showing

This commit is contained in:
Akinwale Ariwodola 2017-06-25 09:14:59 +01:00
parent 7a84b50254
commit 6c2e6727a8
2 changed files with 7 additions and 2 deletions

View file

@ -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`);

View file

@ -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;