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

已关闭
igalic 请求将 6 次代码提交从 igalic/Plume:refactor/extract-searcher-with-dbpool 合并至 main
igalic 评论于 1年前
所有者

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.
igalic1年前 推送了 1 个提交
3b21eb766d
plume-model: refactor Searcher to have its own DbPool
kiwii1年前 批准此合并请求
kiwii 留下了一条评论

👌

let lang = schema.get_field("lang").unwrap();
let license = schema.get_field("license").unwrap();
let conn = self.dbpool.get().unwrap();
kiwii 评论于 1年前
发布者
所有者

I would prefer using ? instead of unwrap here.

I would prefer using `?` instead of `unwrap` here.
igalic 评论于 1年前
发布者
所有者

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 评论于 1年前
发布者
所有者

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 评论于 1年前
发布者
所有者

Same here.

Same here.
kiwii1年前 推送了 1 个提交
igalic 评审于 1年前
igalic 留下了一条评论

👀

Io(std::io::Error),
MissingApProperty,
NotFound,
DbPool,
igalic 评论于 1年前
发布者
所有者

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

you're not trying to convert the original `diesel::r2d2::Error`?
kiwii 评论于 1年前
发布者
所有者

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 评论于 1年前
发布者
所有者

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 评论于 1年前
发布者
所有者

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
kiwii1年前 推送了 1 个提交
39ca7da3f0 Introduce Searcher::new
igalic 评审于 1年前
igalic 留下了一条评论

🙋🏻‍♀️

///
/// 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 评论于 1年前
发布者
所有者

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
kiwii1年前 推送了 1 个提交
igalic1年前 推送了 1 个提交
igalic 1年前 强制从 9309ed279f 推送 refactor/extract-searcher-with-dbpool 到 a5c81498b2
igalic1年前 推送了 1 个提交
igalic 评论于 1年前
发布者
所有者

closing in favour of #813

closing in favour of #813
igalic 关闭此合并请求 1年前

评审人

kiwii1年前 批准此合并请求
请重新打开此拉请求执行合并。
登录 并参与到对话中。
无审核者
未选择里程碑
未指派成员
2 名参与者
通知
到期时间

未设置到期时间。

依赖工单

此合并请求当前没有任何依赖。

正在加载...
这个人很懒,什么都没留下。