consistent renaming, remove a slightly wrong comment

This commit is contained in:
Mike Dilger 2024-03-05 08:44:54 +13:00
parent 437782e770
commit 37d97b5abc

View File

@ -25,7 +25,7 @@ pub struct Store {
ci_index: Database<UnalignedSlice<u8>, OwnedType<usize>>, ci_index: Database<UnalignedSlice<u8>, OwnedType<usize>>,
akc_index: Database<UnalignedSlice<u8>, OwnedType<usize>>, akc_index: Database<UnalignedSlice<u8>, OwnedType<usize>>,
atc_index: Database<UnalignedSlice<u8>, OwnedType<usize>>, atc_index: Database<UnalignedSlice<u8>, OwnedType<usize>>,
kt_index: Database<UnalignedSlice<u8>, OwnedType<usize>>, ktc_index: Database<UnalignedSlice<u8>, OwnedType<usize>>,
deleted_offsets: Database<U64<BigEndian>, Unit>, deleted_offsets: Database<U64<BigEndian>, Unit>,
deleted_events: Database<UnalignedSlice<u8>, Unit>, deleted_events: Database<UnalignedSlice<u8>, Unit>,
ip_data: Database<UnalignedSlice<u8>, UnalignedSlice<u8>>, ip_data: Database<UnalignedSlice<u8>, UnalignedSlice<u8>>,
@ -81,7 +81,7 @@ impl Store {
.types::<UnalignedSlice<u8>, OwnedType<usize>>() .types::<UnalignedSlice<u8>, OwnedType<usize>>()
.name("atci") .name("atci")
.create(&mut txn)?; .create(&mut txn)?;
let kt_index = env let ktc_index = env
.database_options() .database_options()
.types::<UnalignedSlice<u8>, OwnedType<usize>>() .types::<UnalignedSlice<u8>, OwnedType<usize>>()
.name("ktci") .name("ktci")
@ -125,7 +125,7 @@ impl Store {
ci_index, ci_index,
akc_index, akc_index,
atc_index, atc_index,
kt_index, ktc_index,
deleted_offsets, deleted_offsets,
deleted_events, deleted_events,
ip_data, ip_data,
@ -411,14 +411,14 @@ impl Store {
if let Some(tag0) = tag.next() { if let Some(tag0) = tag.next() {
if let Some(tagvalue) = tag.next() { if let Some(tagvalue) = tag.next() {
let iter = { let iter = {
let start_prefix = Self::key_kt_index( let start_prefix = Self::key_ktc_index(
kind, kind,
tag0[0], tag0[0],
tagvalue, tagvalue,
filter.until(), // scan goes backwards in time filter.until(), // scan goes backwards in time
Id([0; 32]), Id([0; 32]),
); );
let end_prefix = Self::key_kt_index( let end_prefix = Self::key_ktc_index(
kind, kind,
tag0[0], tag0[0],
tagvalue, tagvalue,
@ -429,7 +429,7 @@ impl Store {
Bound::Included(&*start_prefix), Bound::Included(&*start_prefix),
Bound::Excluded(&*end_prefix), Bound::Excluded(&*end_prefix),
); );
self.kt_index.range(&txn, &range)? self.ktc_index.range(&txn, &range)?
}; };
// Count how many we have found of this kind-tag pair, so we // Count how many we have found of this kind-tag pair, so we
@ -470,17 +470,13 @@ impl Store {
} else { } else {
// SCRAPE: // SCRAPE:
let maxtime = filter.until().0.min(Time::now().0); let maxtime = filter.until().0.min(Time::now().0);
let allow = self.allow_scraping || let allow = self.allow_scraping
filter.limit() <= self.allow_scrape_if_limited_to || || filter.limit() <= self.allow_scrape_if_limited_to
(maxtime - filter.since().0) < self.allow_scrape_if_max_seconds; || (maxtime - filter.since().0) < self.allow_scrape_if_max_seconds;
if !allow { if !allow {
return Err(ChorusError::Scraper.into()); return Err(ChorusError::Scraper.into());
} }
// FIXME: we can use akc_index to scan author + time
// we can use kt_index to scan kind + time
// (but we have no index yet to scan tag + time)
// This is INEFFICIENT as it scans through many events // This is INEFFICIENT as it scans through many events
let start_prefix = Self::key_ci_index( let start_prefix = Self::key_ci_index(
@ -565,9 +561,9 @@ impl Store {
)?; )?;
// Index by kind and tag (with created_at and id) // Index by kind and tag (with created_at and id)
self.kt_index.put( self.ktc_index.put(
txn, txn,
&Self::key_kt_index( &Self::key_ktc_index(
event.kind(), event.kind(),
tagname[0], tagname[0],
tagvalue, tagvalue,
@ -604,9 +600,9 @@ impl Store {
)?; )?;
// Index by kind and tag (with created_at and id) // Index by kind and tag (with created_at and id)
self.kt_index.delete( self.ktc_index.delete(
txn, txn,
&Self::key_kt_index( &Self::key_ktc_index(
event.kind(), event.kind(),
tagname[0], tagname[0],
tagvalue, tagvalue,
@ -801,7 +797,13 @@ impl Store {
// For looking up event by Kind and Tag // For looking up event by Kind and Tag
// kind(2) + tagletter(1) + fixlentag(182) + reversecreatedat(8) + id(32) // kind(2) + tagletter(1) + fixlentag(182) + reversecreatedat(8) + id(32)
fn key_kt_index(kind: Kind, letter: u8, tag_value: &[u8], created_at: Time, id: Id) -> Vec<u8> { fn key_ktc_index(
kind: Kind,
letter: u8,
tag_value: &[u8],
created_at: Time,
id: Id,
) -> Vec<u8> {
const PADLEN: usize = 182; const PADLEN: usize = 182;
let mut key: Vec<u8> = Vec::with_capacity( let mut key: Vec<u8> = Vec::with_capacity(
std::mem::size_of::<Kind>() std::mem::size_of::<Kind>()