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

Закрыто
igalic хочет смерджить 6 коммит(ов) из igalic/Plume:refactor/extract-searcher-with-dbpool в main
igalic прокомментировал 4 месяцев назад

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.
kiwii одобрил(а) эти изменения 4 месяцев назад
kiwii оставил комментарий

👌

plume-models/src/search/searcher.rs
@@ -175,15 +186,16 @@ impl Searcher {
let lang = schema.get_field("lang").unwrap();
let license = schema.get_field("license").unwrap();

let conn = self.dbpool.get().unwrap();
kiwii прокомментировал 4 месяцев назад

I would prefer using ? instead of unwrap here.

I would prefer using `?` instead of `unwrap` here.
igalic прокомментировал 4 месяцев назад

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 прокомментировал 4 месяцев назад

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.
plume-models/src/search/searcher.rs
@@ -222,24 +229,27 @@ impl Searcher {
let searcher = self.reader.searcher();
let res = searcher.search(&query.into_query(), &collector).unwrap();

let conn = self.dbpool.get().unwrap();
kiwii прокомментировал 4 месяцев назад

Same here.

Same here.
igalic рассмотрел(а) изменения 4 месяцев назад
igalic оставил комментарий

👀

plume-models/src/lib.rs
@@ -40,6 +40,7 @@ pub enum Error {
Io(std::io::Error),
MissingApProperty,
NotFound,
DbPool,
igalic прокомментировал 4 месяцев назад

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

you're not trying to convert the original `diesel::r2d2::Error`?
kiwii прокомментировал 4 месяцев назад

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 прокомментировал 4 месяцев назад

gonna have to ask somebody how the heck this is happening

gonna have to ask somebody how the heck this is happening
plume-models/src/search/searcher.rs
@@ -177,1 +188,4 @@

let conn = match self.dbpool.get() {
Ok(c) => c,
Err(_) => return Err(Error::DbPool),
igalic прокомментировал 4 месяцев назад

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
igalic рассмотрел(а) изменения 4 месяцев назад
igalic оставил комментарий

🙋🏻‍♀️

plume-models/src/search/searcher.rs
@@ -31,0 +55,4 @@
///
/// 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 прокомментировал 4 месяцев назад

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
igalic прокомментировал 4 месяцев назад
Владелец

closing in favour of #813

closing in favour of #813
igalic closed this pull request 4 месяцев назад

Рецензенты

kiwii одобрил(а) эти изменения 4 месяцев назад
Пожалуйста, переоткройте этот Pull Request для выполнения слияния.
Войдите, чтобы присоединиться к обсуждению.
Нет рецензентов
Нет этапа
Нет назначенных лиц
2 участников
Уведомления
Срок выполнения

Срок выполнения не установлен.

Зависимости

Этот запрос на слияние в настоящее время не имеет никаких зависимостей.

Загрузка…
Пока нет содержимого.