···6use crate::indexer::types::{AggregateDeltaStore, RecordTypes};
7use crate::{db, indexer};
8use deadpool_postgres::Transaction;
9-use futures::TryStreamExt;
10use ipld_core::cid::Cid;
11use iroh_car::CarReader;
12use metrics::counter;
13use parakeet_index::AggregateType;
14-use reqwest::Client;
15use std::collections::HashMap;
16-use std::io::ErrorKind;
17use tokio::io::BufReader;
18-use tokio_util::io::StreamReader;
1920type BackfillDeltaStore = HashMap<(String, i32), i32>;
2122-pub async fn stream_and_insert_repo(
23 t: &mut Transaction<'_>,
24- client: &Client,
25 repo: &str,
26- pds: &str,
27) -> eyre::Result<(CarCommitEntry, BackfillDeltaStore, CopyStore)> {
28- let res = client
29- .get(format!("{pds}/xrpc/com.atproto.sync.getRepo?did={repo}"))
30- .send()
31- .await?
32- .error_for_status()?;
33-34- let strm = res
35- .bytes_stream()
36- .map_err(|err| std::io::Error::new(ErrorKind::Other, err));
37- let reader = StreamReader::new(strm);
38- let mut car_stream = CarReader::new(BufReader::new(reader)).await?;
3940 // the root should be the commit block
41 let root = car_stream.header().roots().first().cloned().unwrap();
···6use crate::indexer::types::{AggregateDeltaStore, RecordTypes};
7use crate::{db, indexer};
8use deadpool_postgres::Transaction;
09use ipld_core::cid::Cid;
10use iroh_car::CarReader;
11use metrics::counter;
12use parakeet_index::AggregateType;
013use std::collections::HashMap;
14+use std::path::Path;
15use tokio::io::BufReader;
01617type BackfillDeltaStore = HashMap<(String, i32), i32>;
1819+pub async fn insert_repo(
20 t: &mut Transaction<'_>,
21+ tmp_dir: &Path,
22 repo: &str,
023) -> eyre::Result<(CarCommitEntry, BackfillDeltaStore, CopyStore)> {
24+ let car = tokio::fs::File::open(tmp_dir.join(repo)).await?;
25+ let mut car_stream = CarReader::new(BufReader::new(car)).await?;
0000000002627 // the root should be the commit block
28 let root = car_stream.header().roots().first().cloned().unwrap();
+16-2
consumer/src/config.rs
···40 /// You can use this to move handle resolution out of event handling and into another place.
41 #[serde(default)]
42 pub skip_handle_validation: bool,
00043}
4445#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Deserialize)]
···57 pub backfill_workers: u8,
58 #[serde(default)]
59 pub skip_aggregation: bool,
60- #[serde(default)]
61- pub skip_handle_validation: bool,
00062}
6364fn default_backfill_workers() -> u8 {
···68fn default_indexer_workers() -> u8 {
69 4
70}
00000000
···40 /// You can use this to move handle resolution out of event handling and into another place.
41 #[serde(default)]
42 pub skip_handle_validation: bool,
43+ /// Whether to submit backfill requests for new repos. (Only when history_mode == BackfillHistory).
44+ #[serde(default)]
45+ pub request_backfill: bool,
46}
4748#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Deserialize)]
···60 pub backfill_workers: u8,
61 #[serde(default)]
62 pub skip_aggregation: bool,
63+ #[serde(default = "default_download_workers")]
64+ pub download_workers: usize,
65+ #[serde(default = "default_download_buffer")]
66+ pub download_buffer: usize,
67+ pub download_tmp_dir: String,
68}
6970fn default_backfill_workers() -> u8 {
···74fn default_indexer_workers() -> u8 {
75 4
76}
77+78+fn default_download_workers() -> usize {
79+ 25
80+}
81+82+fn default_download_buffer() -> usize {
83+ 25_000
84+}
+8-3
consumer/src/indexer/mod.rs
···30pub struct RelayIndexerOpts {
31 pub history_mode: HistoryMode,
32 pub skip_handle_validation: bool,
033}
3435#[derive(Clone)]
···38 resolver: Arc<Resolver>,
39 do_backfill: bool,
40 do_handle_res: bool,
041}
4243pub struct RelayIndexer {
···66 state: RelayIndexerState {
67 resolver,
68 do_backfill: opts.history_mode == HistoryMode::BackfillHistory,
069 do_handle_res: !opts.skip_handle_validation,
70 idxc_tx,
71 },
···275 .map(ActorStatus::from)
276 .unwrap_or(ActorStatus::Active);
277278- let trigger_bf = if state.do_backfill && status == ActorStatus::Active {
279 // check old status - if they exist (Some(*)), AND were previously != Active but not Deleted,
280 // AND have a rev == null, then trigger backfill.
281 db::actor_get_status_and_rev(conn, &account.did)
···325 // backfill for them and they can be marked active and indexed normally.
326 // TODO: bridgy doesn't implement since atm - we need a special case
327 if commit.since.is_some() {
328- if state.do_backfill {
329 rc.rpush::<_, _, i32>("backfill_queue", commit.repo).await?;
330 }
331 return Ok(());
···356 .await?;
357358 if trigger_backfill {
359- rc.rpush::<_, _, i32>("backfill_queue", commit.repo).await?;
00360 return Ok(());
361 }
362
···30pub struct RelayIndexerOpts {
31 pub history_mode: HistoryMode,
32 pub skip_handle_validation: bool,
33+ pub request_backfill: bool,
34}
3536#[derive(Clone)]
···39 resolver: Arc<Resolver>,
40 do_backfill: bool,
41 do_handle_res: bool,
42+ req_backfill: bool,
43}
4445pub struct RelayIndexer {
···68 state: RelayIndexerState {
69 resolver,
70 do_backfill: opts.history_mode == HistoryMode::BackfillHistory,
71+ req_backfill: opts.request_backfill,
72 do_handle_res: !opts.skip_handle_validation,
73 idxc_tx,
74 },
···278 .map(ActorStatus::from)
279 .unwrap_or(ActorStatus::Active);
280281+ let trigger_bf = if state.do_backfill && state.req_backfill && status == ActorStatus::Active {
282 // check old status - if they exist (Some(*)), AND were previously != Active but not Deleted,
283 // AND have a rev == null, then trigger backfill.
284 db::actor_get_status_and_rev(conn, &account.did)
···328 // backfill for them and they can be marked active and indexed normally.
329 // TODO: bridgy doesn't implement since atm - we need a special case
330 if commit.since.is_some() {
331+ if state.do_backfill && state.req_backfill {
332 rc.rpush::<_, _, i32>("backfill_queue", commit.repo).await?;
333 }
334 return Ok(());
···359 .await?;
360361 if trigger_backfill {
362+ if state.req_backfill {
363+ rc.rpush::<_, _, i32>("backfill_queue", commit.repo).await?;
364+ }
365 return Ok(());
366 }
367
+1
consumer/src/main.rs
···115 let indexer_opts = indexer::RelayIndexerOpts {
116 history_mode: indexer_cfg.history_mode,
117 skip_handle_validation: indexer_cfg.skip_handle_validation,
0118 };
119120 let relay_indexer = indexer::RelayIndexer::new(