Skip to content

Commit

Permalink
Merge pull request #1666 from nervosnetwork/develop
Browse files Browse the repository at this point in the history
Deploy to testnet
  • Loading branch information
zmcNotafraid authored Mar 5, 2024
2 parents 26e4a0f + cd72034 commit 36e89b0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
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

0 comments on commit 36e89b0

Please sign in to comment.