debug: add subid debugging

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin 2024-09-03 11:10:59 -07:00
parent 2603d08d1a
commit 043ccf2146
4 changed files with 32 additions and 7 deletions

View File

@ -68,6 +68,7 @@ pub struct Damus {
// TODO: make these flags
is_mobile: bool,
pub debug: bool,
pub since_optimize: bool,
pub textmode: bool,
pub show_account_switcher: bool,
@ -148,7 +149,7 @@ fn send_initial_timeline_filter(damus: &mut Damus, timeline: usize) {
filter
}).collect();
let sub_id = Uuid::new_v4().to_string();
let sub_id = damus.gen_subid(&SubKind::Initial);
damus
.subscriptions()
.insert(sub_id.clone(), SubKind::Initial);
@ -158,16 +159,15 @@ fn send_initial_timeline_filter(damus: &mut Damus, timeline: usize) {
// we need some data first
FilterState::NeedsRemote(filter) => {
let sub_id = Uuid::new_v4().to_string();
let uid = damus.timelines[timeline].uid;
let sub_kind = SubKind::FetchingContactList(uid);
let sub_id = damus.gen_subid(&sub_kind);
let local_sub = damus.ndb.subscribe(&filter).expect("sub");
damus.timelines[timeline].filter =
FilterState::fetching_remote(sub_id.clone(), local_sub);
damus
.subscriptions()
.insert(sub_id.clone(), SubKind::FetchingContactList(uid));
damus.subscriptions().insert(sub_id.clone(), sub_kind);
damus.pool.subscribe(sub_id, filter.to_owned());
}
@ -341,7 +341,8 @@ fn is_timeline_ready(damus: &mut Damus, timeline: usize) -> Result<bool> {
setup_initial_timeline(damus, timeline, &filter).expect("setup init");
damus.timelines[timeline].filter = FilterState::ready(filter.clone());
let subid = Uuid::new_v4().to_string();
let ck = &damus.timelines[timeline].kind;
let subid = damus.gen_subid(&SubKind::Column(ck.clone()));
damus.pool.subscribe(subid, filter)
}
}
@ -457,6 +458,9 @@ fn handle_eose(damus: &mut Damus, subid: &str, relay_url: &str) -> Result<()> {
};
match *sub_kind {
SubKind::Column(_) => {
// eose on column? whatevs
}
SubKind::Initial => {
let txn = Transaction::new(&damus.ndb)?;
UnknownIds::update(&txn, damus);
@ -637,8 +641,11 @@ impl Damus {
}
}
let debug = parsed_args.debug;
Self {
pool,
debug,
is_mobile,
unknown_ids: UnknownIds::default(),
subscriptions: Subscriptions::default(),
@ -660,6 +667,14 @@ impl Damus {
}
}
pub fn gen_subid(&self, kind: &SubKind) -> String {
if self.debug {
format!("{:?}", kind)
} else {
Uuid::new_v4().to_string()
}
}
pub fn mock<P: AsRef<Path>>(data_path: P, is_mobile: bool) -> Self {
let mut timelines: Vec<Timeline> = vec![];
let filter = Filter::from_json(include_str!("../queries/global.json")).unwrap();
@ -670,11 +685,13 @@ impl Damus {
let imgcache_dir = data_path.as_ref().join(ImageCache::rel_datadir());
let _ = std::fs::create_dir_all(imgcache_dir.clone());
let debug = true;
let mut config = Config::new();
config.set_ingester_threads(2);
Self {
is_mobile,
debug,
unknown_ids: UnknownIds::default(),
subscriptions: Subscriptions::default(),
since_optimize: true,

View File

@ -12,6 +12,7 @@ pub struct Args {
pub keys: Vec<Keypair>,
pub since_optimize: bool,
pub light: bool,
pub debug: bool,
pub dbpath: Option<String>,
}
@ -24,6 +25,7 @@ impl Args {
keys: vec![],
light: false,
since_optimize: true,
debug: false,
dbpath: None,
};
@ -38,6 +40,8 @@ impl Args {
res.light = true;
} else if arg == "--dark" {
res.light = false;
} else if arg == "--debug" {
res.debug = true;
} else if arg == "--pub" || arg == "--npub" {
i += 1;
let pubstr = if let Some(next_arg) = args.get(i) {

View File

@ -13,7 +13,7 @@ pub enum PubkeySource {
DeckAuthor,
}
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum ListKind {
Contact(PubkeySource),
}

View File

@ -1,5 +1,7 @@
use std::collections::HashMap;
use crate::column::ColumnKind;
#[derive(Debug, Clone)]
pub enum SubKind {
/// Initial subscription. This is the first time we do a remote subscription
/// for a timeline
@ -8,6 +10,8 @@ pub enum SubKind {
/// One shot requests, we can just close after we receive EOSE
OneShot,
Column(ColumnKind),
/// We are fetching a contact list so that we can use it for our follows
/// Filter.
// TODO: generalize this to any list?