Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove unused nfts_count column from the collection_traits table #678

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions app/Data/Collections/CollectionTraitData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,7 +26,6 @@ public function __construct(
public string|float $value,
public ?float $valueMin,
public ?float $valueMax,
public float $nftsCount,
public float $nftsPercentage,
) {
}
Expand All @@ -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'],
);
}
Expand Down
1 change: 0 additions & 1 deletion app/Data/Web3/Web3CollectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
Expand Down
2 changes: 0 additions & 2 deletions app/Http/Client/Mnemonic/MnemonicPendingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
));
Expand All @@ -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),
));
Expand Down
1 change: 0 additions & 1 deletion app/Models/CollectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class CollectionTrait extends Model
'value_min',
'value_max',
'nfts_percentage',
'nfts_count',
];

protected $casts = [
Expand Down
6 changes: 1 addition & 5 deletions app/Support/Web3CollectionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}
6 changes: 1 addition & 5 deletions app/Support/Web3NftHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ private function getChainId(): int
/**
* @param Collection<int, Web3NftData> $nfts
* @param Collection<string, \App\Models\Collection> $collectionLookup
* NOTE: The caller is responsible for ensuring atomicity. Make sure to always call this inside a `DB::Transaction`.
crnkovic marked this conversation as resolved.
Show resolved Hide resolved
*/
public function upsertTraits(Collection $nfts, Collection $collectionLookup, Carbon $now): void
{
Expand Down Expand Up @@ -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()));
Expand Down
1 change: 0 additions & 1 deletion database/factories/CollectionTraitFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('collection_traits', function (Blueprint $table) {
$table->dropColumn('nfts_count');
});
}
};
1 change: 0 additions & 1 deletion database/seeders/LiveUserSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion database/seeders/TopCollectionsNftsSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
]);

Expand Down
12 changes: 4 additions & 8 deletions queries/nfts.insert_collection_traits.sql
Original file line number Diff line number Diff line change
@@ -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
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export default class CollectionTraitDataFactory extends ModelFactory<App.Data.Co
nftsPercentage: faker.datatype.float({ min: 0, max: 100 }),
valueMax: faker.datatype.number(),
valueMin: faker.datatype.number(),
nftsCount: faker.datatype.number(),
};
}
}
1 change: 0 additions & 1 deletion resources/types/generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ declare namespace App.Data.Collections {
/** 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;
};
export type CollectionTraitFilterData = {
Expand Down
Loading