plume-model: refactor Searcher to have its own DbPool #809

Zamknięty
igalic chce scalić 6 commity/ów z igalic/Plume:refactor/extract-searcher-with-dbpool do main
igalic skomentował(-a) 1 rok temu
Właściciel

This PR is another attempt at fixing #799

Instead of relying on a separate actor model, as described, we make use of the fact that DbPool is an Arc, and can be arbitrarily cloned, so we add it to Searcher. Further more, and db_pool.get() acts like sending a message to an Actor: if there are enough connections, the Pool gives us one, if not, tough luck!

this way, we don't need to pass along a conn into the searcher functions.
This should make splitting PlumeRocket up into its components a little easier.

This PR is another attempt at fixing #799 Instead of relying on a separate actor model, as described, we make use of the fact that DbPool is an `Arc`, and can be arbitrarily cloned, so we add it to `Searcher`. Further more, and `db_pool.get()` *acts* like sending a message to an Actor: if there are enough connections, the Pool gives us one, if not, tough luck! this way, we don't need to pass along a conn into the searcher functions. This should make splitting PlumeRocket up into its components a little easier.
igalic dodał(-a) 1 commit 1 rok temu
3b21eb766d
plume-model: refactor Searcher to have its own DbPool
kiwii zatwierdza te zmiany 1 rok temu
kiwii zostawił komentarz

👌

let lang = schema.get_field("lang").unwrap();
let license = schema.get_field("license").unwrap();
let conn = self.dbpool.get().unwrap();
kiwii skomentował(-a) 1 rok temu
Autor
Właściciel

I would prefer using ? instead of unwrap here.

I would prefer using `?` instead of `unwrap` here.
igalic skomentował(-a) 1 rok temu
Autor
Właściciel

can you briefly explain why?

we use .unwrap() in all other lines.

can you briefly explain why? we use `.unwrap()` in all other lines.
kiwii skomentował(-a) 1 rok temu
Autor
Właściciel

I think all the previous ones are safe: we now it can't panic because we control the search index schema, we know that these fields exist (even if Rust can't check this at comoile-time). Here, we may fail to get a DB connection from the pool for whatever reason, and I think we should make the error "go up", so that the web UI or the CLI can display a proper error.

I think all the previous ones are safe: we now it can't panic because we control the search index schema, we know that these fields exist (even if Rust can't check this at comoile-time). Here, we may fail to get a DB connection from the pool for whatever reason, and I think we should make the error "go up", so that the web UI or the CLI can display a proper error.
let searcher = self.reader.searcher();
let res = searcher.search(&query.into_query(), &collector).unwrap();
let conn = self.dbpool.get().unwrap();
kiwii skomentował(-a) 1 rok temu
Autor
Właściciel

Same here.

Same here.
kiwii dodał(-a) 1 commit 1 rok temu
igalic zrecenzowano 1 rok temu
igalic zostawił komentarz

👀

Io(std::io::Error),
MissingApProperty,
NotFound,
DbPool,
igalic skomentował(-a) 1 rok temu
Autor
Właściciel

you're not trying to convert the original diesel::r2d2::Error?

you're not trying to convert the original `diesel::r2d2::Error`?
kiwii skomentował(-a) 1 rok temu
Autor
Właściciel

It is a r2d2::Error, not the same as Diesel's one apparently. And I don't want to add another direct dependency in our Cargo.toml.

It is a `r2d2::Error`, not the same as Diesel's one apparently. And I don't want to add another direct dependency in our Cargo.toml.
igalic skomentował(-a) 1 rok temu
Autor
Właściciel

gonna have to ask somebody how the heck this is happening

gonna have to ask somebody how the heck this is happening
let conn = match self.dbpool.get() {
Ok(c) => c,
Err(_) => return Err(Error::DbPool),
igalic skomentował(-a) 1 rok temu
Autor
Właściciel

that means we won't know exactly why the pool didn't give us a connection

that means we won't know exactly why the pool didn't give us a connection
kiwii dodał(-a) 1 commit 1 rok temu
39ca7da3f0 Introduce Searcher::new
igalic zrecenzowano 1 rok temu
igalic zostawił komentarz

🙋🏻‍♀️

///
/// The panic messages are normally explicit enough for a human to
/// understand how to fix the issue when they see it.
pub fn new(db_pool: DbPool) -> Arc<Self> {
igalic skomentował(-a) 1 rok temu
Autor
Właściciel

why are we returning Arc<Self>?
this means our code needs to know exactly how it's going to be used

what about cli? does that use an Arc?

i would use this function to only return a Self
there's no need to init_pool, we just want a copy

we can create an initialize method, which tries to call open and create methods in the appropriate order with the error recovery, if that makes sense here

but as it stands, for a new function, this does too much

why are we returning `Arc<Self>`? this means our code needs to know exactly how it's going to be used what about cli? does that use an Arc? i would use this function to only return a Self there's no need to init_pool, we just want a copy we can create an initialize method, which tries to call open and create *methods* in the appropriate order with the error recovery, if that makes sense here but as it stands, for a new function, this does too much
kiwii dodał(-a) 1 commit 1 rok temu
igalic dodał(-a) 1 commit 1 rok temu
igalic przymusowo wypchnął refactor/extract-searcher-with-dbpool z 9309ed279f do a5c81498b2 1 rok temu
igalic dodał(-a) 1 commit 1 rok temu
igalic skomentował(-a) 1 rok temu
Autor
Właściciel

closing in favour of #813

closing in favour of #813
igalic zamknął(-ęła) ten pull request 1 rok temu

Recenzenci

kiwii zatwierdza te zmiany 1 rok temu
Otwórz ponownie ten Pull Request, aby wykonać scalenie.
Zaloguj się, aby dołączyć do tej rozmowy.
Brak recenzentów
Brak kamienia milowego
Brak przypisanych
Uczestnicy 2
Powiadomienia
Termin realizacji

Brak ustawionego terminu realizacji.

Zależności

Ten Pull Request nie zawiera w tej chwili żadnych zależności.

Ładowanie…
Nie ma jeszcze treści.