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

Deploy to mainnet #1668

Merged
merged 3 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 17 additions & 11 deletions app/models/token_item.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class TokenItem < ApplicationRecord
enum status: { normal: 1, burnt: 0 }

belongs_to :collection, class_name: "TokenCollection", counter_cache: :items_count
belongs_to :collection, class_name: "TokenCollection"
belongs_to :owner, class_name: "Address"
belongs_to :cell, class_name: "CellOutput", optional: true
belongs_to :type_script, optional: true
Expand All @@ -10,35 +10,41 @@ class TokenItem < ApplicationRecord
validates :token_id, uniqueness: { scope: :collection_id }

before_save :update_type_script
after_save :update_collection_holders
after_save :update_collection_holders, :update_items_count

def update_type_script
self.type_script_id = cell&.type_script_id
end

def update_collection_holders
holders_count = collection.items.normal.distinct.count(:owner_id)
collection.update(holders_count: holders_count)
collection.update(holders_count:)
end

def as_json(options = {})
# except burnt items
def update_items_count
items_count = collection.items.normal.count
collection.update(items_count:)
end

def as_json(_options = {})
{
id: id,
id:,
token_id: token_id.to_s,
owner: owner.address_hash,
standard: collection.standard,
cell: {
status: cell&.status,
tx_hash: cell&.tx_hash,
cell_index: cell&.cell_index,
data: cell&.data
data: cell&.data,
},
type_script: type_script&.as_json,
name: name,
metadata_url: metadata_url,
icon_url: icon_url,
created_at: created_at,
updated_at: updated_at
name:,
metadata_url:,
icon_url:,
created_at:,
updated_at:,
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ namespace :migration do
progress_bar = ProgressBar.create({ total: total_count, format: "%e %B %p%% %c/%C" })

TokenCollection.find_each do |collection|
items_count = collection.items.count
TokenCollection.update_counters(collection.id, items_count: items_count)
items_count = collection.items.normal.count
holders_count = collection.items.normal.distinct.count(:owner_id)
collection.update_column(:holders_count, holders_count)
collection.update(holders_count:, items_count:)
progress_bar.increment
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/services/charts/daily_statistic_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class DailyStatisticGeneratorTest < ActiveSupport::TestCase
create(:cell_output, :with_full_transaction,
block_timestamp: @datetime.to_i * 1000, block: @block),
]
CellOutput.where(id: cells.map(&:id)).update_all(consumed_block_timestamp: (@datetime.to_i + 10) * 1000)
CellOutput.where(id: cells.map(&:id)).update_all(consumed_block_timestamp: (@datetime.to_i + 1) * 1000)
is_from_scratch = true
assert_equal "3",
Charts::DailyStatisticGenerator.new(@datetime,
Expand Down
Loading