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

닫힘
igalic igalic/Plume:refactor/extract-searcher-with-dbpool 에서 main 로 6개의 커밋들을 병합하려함
소유자

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 이 변경사항을 승인함 2020-07-23 18:35:10 +00:00
kiwii left a comment
소유자

👌

👌
@ -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();
소유자

I would prefer using ? instead of unwrap here.

I would prefer using `?` instead of `unwrap` here.
작성자
소유자

can you briefly explain why?

we use .unwrap() in all other lines.

can you briefly explain why? we use `.unwrap()` in all other lines.
소유자

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.
@ -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();
소유자

Same here.

Same here.
igalic 검토됨 2020-07-24 14:49:47 +00:00
igalic left a comment
작성자
소유자

👀

👀
@ -40,6 +40,7 @@ pub enum Error {
Io(std::io::Error),
MissingApProperty,
NotFound,
DbPool,
작성자
소유자

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

you're not trying to convert the original `diesel::r2d2::Error`?
소유자

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.
작성자
소유자

gonna have to ask somebody how the heck this is happening

gonna have to ask somebody how the heck this is happening
@ -177,1 +188,4 @@
let conn = match self.dbpool.get() {
Ok(c) => c,
Err(_) => return Err(Error::DbPool),
작성자
소유자

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 검토됨 2020-07-24 15:46:38 +00:00
igalic left a comment
작성자
소유자

🙋🏻‍♀️

🙋🏻‍♀️
@ -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> {
작성자
소유자

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 force-pushed refactor/extract-searcher-with-dbpool from 9309ed279f to a5c81498b2 2020-07-24 20:12:17 +00:00 Compare
igalic added 1 commit 2020-07-25 08:05:45 +00:00
this will not compile, so now it's time to fix the rest
작성자
소유자

closing in favour of #813

closing in favour of #813
igalic closed this pull request 2020-07-26 19:37:26 +00:00

Pull request closed

로그인하여 이 대화에 참여하세요.
No reviewers
마일스톤 없음
프로젝트 없음
담당자 없음
참가자 2명
알림
마감일
기한이 올바르지 않거나 범위를 벗어났습니다. "yyyy-mm-dd"형식을 사용해주십시오.

마감일이 설정되지 않았습니다.

전제조건

전제조건이 설정되지 않았습니다.

Reference: Plume/Plume#809
No description provided.