From e6408fabe0781bde197f1422a628f0a7b16fdd0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josip=20Crnkovi=C4=87?= <6536260+crnkovic@users.noreply.github.com> Date: Mon, 19 Feb 2024 15:32:21 +0100 Subject: [PATCH 1/5] wip --- app/Data/Collections/CollectionTraitData.php | 3 --- app/Data/Web3/Web3CollectionTrait.php | 1 - .../Mnemonic/MnemonicPendingRequest.php | 2 -- app/Models/CollectionTrait.php | 1 - app/Support/Web3CollectionHandler.php | 6 +----- app/Support/Web3NftHandler.php | 6 +----- database/factories/CollectionTraitFactory.php | 1 - ...fts_count_from_collection_traits_table.php | 20 +++++++++++++++++++ database/seeders/LiveUserSeeder.php | 1 - database/seeders/TopCollectionsNftsSeeder.php | 3 +-- queries/nfts.insert_collection_traits.sql | 12 ++++------- .../Factories/CollectionTraitDataFactory.ts | 1 - resources/types/generated.d.ts | 1 - 13 files changed, 27 insertions(+), 31 deletions(-) create mode 100644 database/migrations/2024_02_19_141526_remove_nfts_count_from_collection_traits_table.php diff --git a/app/Data/Collections/CollectionTraitData.php b/app/Data/Collections/CollectionTraitData.php index bcae13d66..0e104cfe8 100644 --- a/app/Data/Collections/CollectionTraitData.php +++ b/app/Data/Collections/CollectionTraitData.php @@ -16,7 +16,6 @@ '/** Use the displayType to infer the actual type. */ value' => 'string | number', '/** Only present for numeric displayTypes. */ valueMin' => '?number', '/** Only present for numeric displayTypes. */ valueMax' => '?number', - 'nftsCount' => 'number', 'nftsPercentage' => 'number', ])] class CollectionTraitData extends Data @@ -27,7 +26,6 @@ public function __construct( public string|float $value, public ?float $valueMin, public ?float $valueMax, - public float $nftsCount, public float $nftsPercentage, ) { } @@ -40,7 +38,6 @@ public static function fromModel(CollectionTrait $trait): self value: self::extractValue($trait), valueMin: $trait['value_min'] ?? null, valueMax: $trait['value_max'] ?? null, - nftsCount: $trait['nfts_count'], nftsPercentage: $trait['nfts_percentage'], ); } diff --git a/app/Data/Web3/Web3CollectionTrait.php b/app/Data/Web3/Web3CollectionTrait.php index f836e79f4..9c75e81d1 100644 --- a/app/Data/Web3/Web3CollectionTrait.php +++ b/app/Data/Web3/Web3CollectionTrait.php @@ -13,7 +13,6 @@ public function __construct( public string $value, public ?float $valueMin, public ?float $valueMax, - public string $nftsCount, public float $nftsPercentage, public TraitDisplayType $displayType, ) { diff --git a/app/Http/Client/Mnemonic/MnemonicPendingRequest.php b/app/Http/Client/Mnemonic/MnemonicPendingRequest.php index d72d5b6ba..4b6ebf7d9 100644 --- a/app/Http/Client/Mnemonic/MnemonicPendingRequest.php +++ b/app/Http/Client/Mnemonic/MnemonicPendingRequest.php @@ -281,7 +281,6 @@ public function getCollectionTraits(Chain $chain, string $contractAddress): Coll value: $trait['value'], valueMin: null, valueMax: null, - nftsCount: $trait['nftsCount'], nftsPercentage: $trait['nftsPercentage'], displayType: TraitDisplayType::fromMnemonicDisplayType($trait['displayType'] ?? null, $trait['value']), )); @@ -297,7 +296,6 @@ public function getCollectionTraits(Chain $chain, string $contractAddress): Coll value: Web3NftHandler::$numericTraitPlaceholder, valueMin: $trait['valueMin'], valueMax: $trait['valueMax'], - nftsCount: $trait['nftsCount'] ?? '0', nftsPercentage: $trait['nftsPercentage'] ?? 0, displayType: TraitDisplayType::fromMnemonicDisplayType($trait['displayType'] ?? null, null), )); diff --git a/app/Models/CollectionTrait.php b/app/Models/CollectionTrait.php index 68fb1a747..299cb4dcf 100644 --- a/app/Models/CollectionTrait.php +++ b/app/Models/CollectionTrait.php @@ -28,7 +28,6 @@ class CollectionTrait extends Model 'value_min', 'value_max', 'nfts_percentage', - 'nfts_count', ]; protected $casts = [ diff --git a/app/Support/Web3CollectionHandler.php b/app/Support/Web3CollectionHandler.php index 872dcc04d..03b73f7fe 100644 --- a/app/Support/Web3CollectionHandler.php +++ b/app/Support/Web3CollectionHandler.php @@ -26,18 +26,14 @@ public function storeTraits(int $collectionId, Collection $traits): void return [ 'collection_id' => $collectionId, 'name' => $trait->name, - 'value' => $trait->value, 'display_type' => $trait->displayType->value, - 'value_min' => $trait->valueMin, 'value_max' => $trait->valueMax, - - 'nfts_count' => $trait->nftsCount, 'nfts_percentage' => $trait->nftsPercentage, ]; })->toArray(), ['collection_id', 'name', 'value'], - ['display_type', 'value_min', 'value_max', 'nfts_count', 'nfts_percentage']); + ['display_type', 'value_min', 'value_max', 'nfts_percentage']); } } diff --git a/app/Support/Web3NftHandler.php b/app/Support/Web3NftHandler.php index ffe11b674..d05f256fe 100644 --- a/app/Support/Web3NftHandler.php +++ b/app/Support/Web3NftHandler.php @@ -300,7 +300,6 @@ private function getChainId(): int /** * @param Collection $nfts * @param Collection $collectionLookup - * NOTE: The caller is responsible for ensuring atomicity. Make sure to always call this inside a `DB::Transaction`. */ public function upsertTraits(Collection $nfts, Collection $collectionLookup, Carbon $now): void { @@ -339,16 +338,13 @@ public function upsertTraits(Collection $nfts, Collection $collectionLookup, Car $trait['normalizedValue'], $trait['displayType']->value, 0, - 0, $now, $now, ]); - $placeholders = $params->map(fn ($_) => '(?, ?, ?, ?, ?, ?, ?, ?)')->join(', '); - $query = sprintf( get_query('nfts.insert_collection_traits'), - $placeholders + $params->map(fn ($_) => '(?, ?, ?, ?, ?, ?, ?)')->join(', ') ); $dbTraits = collect(DB::select($query, $params->flatten()->toArray())); diff --git a/database/factories/CollectionTraitFactory.php b/database/factories/CollectionTraitFactory.php index 001c16f26..67fd71dde 100644 --- a/database/factories/CollectionTraitFactory.php +++ b/database/factories/CollectionTraitFactory.php @@ -43,7 +43,6 @@ public function definition(): array 'value_max' => $valueMax, 'nfts_percentage' => fn () => fake()->randomFloat(3, 0, 100.0), - 'nfts_count' => fn () => random_int(0, 10000), ]; } } diff --git a/database/migrations/2024_02_19_141526_remove_nfts_count_from_collection_traits_table.php b/database/migrations/2024_02_19_141526_remove_nfts_count_from_collection_traits_table.php new file mode 100644 index 000000000..34b337198 --- /dev/null +++ b/database/migrations/2024_02_19_141526_remove_nfts_count_from_collection_traits_table.php @@ -0,0 +1,20 @@ +dropColumn('nfts_count'); + }); + } +}; diff --git a/database/seeders/LiveUserSeeder.php b/database/seeders/LiveUserSeeder.php index bdd628787..f2bb98d26 100644 --- a/database/seeders/LiveUserSeeder.php +++ b/database/seeders/LiveUserSeeder.php @@ -211,7 +211,6 @@ private function ingestCollectionTraitsFixtures(string $fileName): void value: $trait['value'], valueMin: $trait['valueMin'] ?? 0, valueMax: $trait['valueMax'] ?? 0, - nftsCount: $trait['nftsCount'], nftsPercentage: $trait['nftsPercentage'], displayType: TraitDisplayType::from($trait['displayType']), ))->unique(fn ($trait) => '_'.$dbCollection->id.'_'.$trait->name.'_'.$trait->value); diff --git a/database/seeders/TopCollectionsNftsSeeder.php b/database/seeders/TopCollectionsNftsSeeder.php index e5859fc93..1fe5da928 100644 --- a/database/seeders/TopCollectionsNftsSeeder.php +++ b/database/seeders/TopCollectionsNftsSeeder.php @@ -6,8 +6,8 @@ use App\Enums\Chain; use App\Enums\TokenType; -use App\Models\Collection; use App\Models\Collection as NftCollection; +use App\Models\Collection; use App\Models\CollectionTrait; use App\Models\Network; use App\Models\Token; @@ -72,7 +72,6 @@ public function run(): void 'value_max' => $trait['valueMin'], 'value_min' => $trait['valueMax'], 'display_type' => $trait['displayType'], - 'nfts_count' => $trait['nftsCount'], 'nfts_percentage' => $trait['nftsPercentage'], ]); diff --git a/queries/nfts.insert_collection_traits.sql b/queries/nfts.insert_collection_traits.sql index 20ed0ceec..7dfe7813b 100644 --- a/queries/nfts.insert_collection_traits.sql +++ b/queries/nfts.insert_collection_traits.sql @@ -1,9 +1,5 @@ -insert into collection_traits ( - collection_id, name, value, display_type, - nfts_count, nfts_percentage, - created_at, updated_at -) values %s +insert into collection_traits (collection_id, name, value, display_type, nfts_percentage, created_at, updated_at) +values %s on conflict (collection_id, name, value) do update -set nfts_count = (case when excluded.nfts_count > 0 then excluded.nfts_count else collection_traits.nfts_count end), - nfts_percentage = (case when excluded.nfts_percentage > 0 then excluded.nfts_percentage else collection_traits.nfts_percentage end) -returning id, collection_id, name, value \ No newline at end of file +set nfts_percentage = (case when excluded.nfts_percentage > 0 then excluded.nfts_percentage else collection_traits.nfts_percentage end) +returning id, collection_id, name, value diff --git a/resources/js/Tests/Factories/CollectionTraitDataFactory.ts b/resources/js/Tests/Factories/CollectionTraitDataFactory.ts index d56dbd493..628a21476 100644 --- a/resources/js/Tests/Factories/CollectionTraitDataFactory.ts +++ b/resources/js/Tests/Factories/CollectionTraitDataFactory.ts @@ -10,7 +10,6 @@ export default class CollectionTraitDataFactory extends ModelFactory Date: Mon, 19 Feb 2024 14:34:39 +0000 Subject: [PATCH 2/5] style: resolve style guide violations --- database/seeders/TopCollectionsNftsSeeder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/seeders/TopCollectionsNftsSeeder.php b/database/seeders/TopCollectionsNftsSeeder.php index 1fe5da928..5d712e708 100644 --- a/database/seeders/TopCollectionsNftsSeeder.php +++ b/database/seeders/TopCollectionsNftsSeeder.php @@ -6,8 +6,8 @@ use App\Enums\Chain; use App\Enums\TokenType; -use App\Models\Collection as NftCollection; use App\Models\Collection; +use App\Models\Collection as NftCollection; use App\Models\CollectionTrait; use App\Models\Network; use App\Models\Token; From 05d2ef029d42a8e31bdc420699ded8ebaa993cf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josip=20Crnkovi=C4=87?= <6536260+crnkovic@users.noreply.github.com> Date: Wed, 6 Mar 2024 16:00:40 +0100 Subject: [PATCH 3/5] Update Web3NftHandler.php --- app/Support/Web3NftHandler.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Support/Web3NftHandler.php b/app/Support/Web3NftHandler.php index d05f256fe..b174aa6ab 100644 --- a/app/Support/Web3NftHandler.php +++ b/app/Support/Web3NftHandler.php @@ -300,6 +300,7 @@ private function getChainId(): int /** * @param Collection $nfts * @param Collection $collectionLookup + * NOTE: The caller is responsible for ensuring atomicity. Make sure to always call this inside a `DB::Transaction`. */ public function upsertTraits(Collection $nfts, Collection $collectionLookup, Carbon $now): void { From 2f85888e2481cdd4b239a13f10ca8aafa939603c Mon Sep 17 00:00:00 2001 From: crnkovic Date: Wed, 6 Mar 2024 15:03:04 +0000 Subject: [PATCH 4/5] style: resolve style guide violations --- app/Support/Web3NftHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Support/Web3NftHandler.php b/app/Support/Web3NftHandler.php index b3bee8d15..144bececc 100644 --- a/app/Support/Web3NftHandler.php +++ b/app/Support/Web3NftHandler.php @@ -249,7 +249,7 @@ private function getChainId(): int /** * @param Collection $nfts * @param Collection $collectionLookup - * NOTE: The caller is responsible for ensuring atomicity. Make sure to always call this inside a `DB::Transaction`. + * NOTE: The caller is responsible for ensuring atomicity. Make sure to always call this inside a `DB::Transaction`. */ public function upsertTraits(Collection $nfts, Collection $collectionLookup, Carbon $now): void { From 170388009f7a0ce2a23a1bde010c03ecdb89661c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josip=20Crnkovi=C4=87?= <6536260+crnkovic@users.noreply.github.com> Date: Thu, 7 Mar 2024 15:59:23 +0100 Subject: [PATCH 5/5] Update Web3CollectionHandlerTest.php --- tests/App/Support/Web3CollectionHandlerTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/App/Support/Web3CollectionHandlerTest.php b/tests/App/Support/Web3CollectionHandlerTest.php index 281ff0e3d..0b9a81a11 100644 --- a/tests/App/Support/Web3CollectionHandlerTest.php +++ b/tests/App/Support/Web3CollectionHandlerTest.php @@ -16,7 +16,6 @@ value: 'Blue', valueMin: null, valueMax: null, - nftsCount: '0', nftsPercentage: 0, displayType: TraitDisplayType::Property, ); @@ -26,7 +25,6 @@ value: 'Black', valueMin: null, valueMax: null, - nftsCount: '0', nftsPercentage: 0, displayType: TraitDisplayType::Property, );