Skip to content

Commit

Permalink
address nits
Browse files Browse the repository at this point in the history
  • Loading branch information
raphjaph committed Sep 21, 2023
1 parent 58aa9b4 commit 9e7b3e4
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 33 deletions.
34 changes: 20 additions & 14 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ impl Index {
pub(crate) fn get_inscription_ids_by_sat(&self, sat: Sat) -> Result<Vec<InscriptionId>> {
let rtx = &self.database.begin_read()?;

let mut ids = rtx
let ids = rtx
.open_multimap_table(SAT_TO_INSCRIPTION_ID)?
.get(&sat.n())?
.map(|result| {
Expand All @@ -666,20 +666,26 @@ impl Index {

if ids.len() > 1 {
let inscription_id_to_entry = rtx.open_table(INSCRIPTION_ID_TO_INSCRIPTION_ENTRY)?;
ids.sort_by_key(|inscription_id| {
match inscription_id_to_entry
.get(&inscription_id.store())
.unwrap()
.map(|value| InscriptionEntry::load(value.value()))
.map(|entry| entry.sequence_number)
{
Some(num) => num + 1, // remove at next index refactor
_ => 0,
}
});
}

Ok(ids)
let mut seq_nums = Vec::new();
for id in &ids {
seq_nums.push(
InscriptionEntry::load(inscription_id_to_entry.get(&id.store())?.unwrap().value())
.sequence_number,
)
}

let mut ids = seq_nums
.into_iter()
.zip(ids)
.collect::<Vec<(u64, InscriptionId)>>();

ids.sort_by_key(|(sequence_number, _)| *sequence_number);

Ok(ids.into_iter().map(|(_, id)| id).collect())
} else {
Ok(ids)
}
}

pub(crate) fn get_inscription_id_by_sequence_number(
Expand Down
12 changes: 6 additions & 6 deletions src/index/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,12 @@ impl<'index> Updater<'_> {
.map(|lost_sats| lost_sats.value())
.unwrap_or(0);

let num_cursed_inscription = statistic_to_count
let cursed_inscription_count = statistic_to_count
.get(&Statistic::CursedInscriptions.key())?
.map(|count| count.value())
.unwrap_or(0);

let num_blessed_inscriptions = statistic_to_count
let blessed_inscription_count = statistic_to_count
.get(&Statistic::BlessedInscriptions.key())?
.map(|count| count.value())
.unwrap_or(0);
Expand All @@ -416,8 +416,8 @@ impl<'index> Updater<'_> {
value_receiver,
&mut inscription_id_to_inscription_entry,
lost_sats,
num_cursed_inscription,
num_blessed_inscriptions,
cursed_inscription_count,
blessed_inscription_count,
&mut sequence_number_to_inscription_id,
&mut outpoint_to_value,
&mut sat_to_inscription_id,
Expand Down Expand Up @@ -533,12 +533,12 @@ impl<'index> Updater<'_> {

statistic_to_count.insert(
&Statistic::CursedInscriptions.key(),
&inscription_updater.num_cursed_inscriptions,
&inscription_updater.cursed_inscription_count,
)?;

statistic_to_count.insert(
&Statistic::BlessedInscriptions.key(),
&inscription_updater.num_blessed_inscriptions,
&inscription_updater.blessed_inscription_count,
)?;

statistic_to_count.insert(
Expand Down
20 changes: 10 additions & 10 deletions src/index/updater/inscription_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub(super) struct InscriptionUpdater<'a, 'db, 'tx> {
value_receiver: &'a mut Receiver<u64>,
id_to_entry: &'a mut Table<'db, 'tx, &'static InscriptionIdValue, InscriptionEntryValue>,
pub(super) lost_sats: u64,
pub(super) num_cursed_inscriptions: u64,
pub(super) num_blessed_inscriptions: u64,
pub(super) cursed_inscription_count: u64,
pub(super) blessed_inscription_count: u64,
pub(super) next_sequence_number: u64,
sequence_number_to_id: &'a mut Table<'db, 'tx, u64, &'static InscriptionIdValue>,
outpoint_to_value: &'a mut Table<'db, 'tx, &'static OutPointValue, u64>,
Expand All @@ -56,8 +56,8 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
value_receiver: &'a mut Receiver<u64>,
id_to_entry: &'a mut Table<'db, 'tx, &'static InscriptionIdValue, InscriptionEntryValue>,
lost_sats: u64,
num_cursed_inscriptions: u64,
num_blessed_inscriptions: u64,
cursed_inscription_count: u64,
blessed_inscription_count: u64,
sequence_number_to_id: &'a mut Table<'db, 'tx, u64, &'static InscriptionIdValue>,
outpoint_to_value: &'a mut Table<'db, 'tx, &'static OutPointValue, u64>,
sat_to_inscription_id: &'a mut MultimapTable<'db, 'tx, u64, &'static InscriptionIdValue>,
Expand Down Expand Up @@ -86,8 +86,8 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
value_receiver,
id_to_entry,
lost_sats,
num_cursed_inscriptions,
num_blessed_inscriptions,
cursed_inscription_count,
blessed_inscription_count,
next_sequence_number,
sequence_number_to_id,
outpoint_to_value,
Expand Down Expand Up @@ -408,14 +408,14 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
unbound,
} => {
let inscription_number = if cursed {
let number: i64 = self.num_cursed_inscriptions.try_into().unwrap();
self.num_cursed_inscriptions += 1;
let number: i64 = self.cursed_inscription_count.try_into().unwrap();
self.cursed_inscription_count += 1;

// because cursed numbers start at -1
-(number + 1)
} else {
let number: i64 = self.num_blessed_inscriptions.try_into().unwrap();
self.num_blessed_inscriptions += 1;
let number: i64 = self.blessed_inscription_count.try_into().unwrap();
self.blessed_inscription_count += 1;

number
};
Expand Down
6 changes: 3 additions & 3 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,10 +994,10 @@ impl Server {
)
};

let previous = if entry.sequence_number == 0 {
None
let previous = if let Some(n) = entry.sequence_number.checked_sub(1) {
index.get_inscription_id_by_sequence_number(n)?
} else {
index.get_inscription_id_by_sequence_number(entry.sequence_number - 1)?
None
};

let next = index.get_inscription_id_by_sequence_number(entry.sequence_number + 1)?;
Expand Down

0 comments on commit 9e7b3e4

Please sign in to comment.