-
Notifications
You must be signed in to change notification settings - Fork 2
Initial Version #2
Conversation
src/db/models.rs
Outdated
.filter(pushboxv1::device_id.eq(device_id.clone())), | ||
).execute(conn) | ||
.context(HandlerErrorKind::DBError) | ||
.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will never fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may, but IIUC, the context()
function captures the error and handles it as a HandleErrorKind::DBError
https://boats.gitlab.io/failure/doc/failure/trait.Fail.html#method.context Although, I admit that it's through the failure
crate, so there's some voodoo going on there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right you'll convert the diesel Error into a failure here but you still ultimately end up with a Result that you don't want to unwrap() (panic).
This function already returns a HandlerError so instead propagate it out via try!: .context(HandlerErrorKind::DBError)?;
src/db/models.rs
Outdated
.filter(pushboxv1::service.eq(service.clone())), | ||
).execute(conn) | ||
.context(HandlerErrorKind::DBError) | ||
.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bare unwrap?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above. The context
should provide additional handling information.
2fb1ab2
to
038cc33
Compare
src/server.rs
Outdated
.unwrap_or(-1); | ||
if decoded > -1 { | ||
match key.to_lowercase().as_str() { | ||
"index" => opt.index = Some(decoded.clone()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: don't need to call .clone() on these primitives here (they are Copy types)
src/server.rs
Outdated
|
||
#[derive(Debug)] | ||
pub struct Options { | ||
pub index: Option<i64>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: these and default_ttl could really be u64s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, except that diesel maps BigInt to i64 http://docs.diesel.rs/src/diesel/sql_types/mod.rs#102, and changing to u64 triggers a compiler issue:
the trait `diesel::Expression` is not implemented for `u64`
so i64 it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
meh, going to hack around it. Not using u64s bugs me too.
src/server.rs
Outdated
} | ||
Ok(Json(json!({ | ||
"last": is_last, | ||
"index": max_index.clone(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
src/server.rs
Outdated
let messages = match DatabaseManager::read_records(&conn, &user_id, &device_id, &service, 0, 0) | ||
{ | ||
Ok(val) => val, | ||
Err(e) => return Err(e), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this match statement and the one in DatabaseManager::new_record should be killed for try! (let messages = ...)?;)
src/db/models.rs
Outdated
.expect("Could not create transaction"); | ||
insert_into(pushboxv1::table) | ||
.values(( | ||
pushboxv1::user_id.eq(user_id.to_string()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
none of the to_string or cloned calls are needed for these diesel queries, it's ok w/ &strs
src/server.rs
Outdated
&data.data, | ||
calc_ttl(data.ttl), | ||
); | ||
if response.is_err() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here and in delete, you can replace these 3 lines by using the ? operator on the previous statement
src/auth.rs
Outdated
// There is no other way to get the rocket.config() from inside a request | ||
// handler. | ||
let config = request.guard::<State<RustboxConfig>>().unwrap(); | ||
let fxa_host = config.fxa_host.clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could be referenced (= &config.fxa_host) vs clone()'d
src/server.rs
Outdated
&data.data, | ||
calc_ttl(data.ttl), | ||
); | ||
if response.is_err() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same w/ these, just use ? on previous statement
src/auth.rs
Outdated
)) | ||
} | ||
}; | ||
if raw_resp.status().is_success() == false { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!raw_resp.status().is_success()
src/auth.rs
Outdated
fn test_valid() { | ||
let mut test_data = Table::new(); | ||
let mut fxa_response = Table::new(); | ||
fxa_response.insert("user".to_owned(), "test".to_owned().into()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can replace .to_owned.into() with just .into() for all these values
src/server.rs
Outdated
} | ||
Ok(Json(json!({ | ||
"last": is_last, | ||
"index": max_index.clone(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't "index" returned here the last index in the current batch we are returning to the client? So it knows where it left off. max_index here is the last index of all messages, which isn't right.
src/db/models.rs
Outdated
service: &String, | ||
) -> HandlerResult<bool> { | ||
// boxed deletes are "coming soon" | ||
// see https://github.com/diesel-rs/diesel/pull/1534 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they're here! 1.2.0 was just released w/ them
6c36751
to
85ed73c
Compare
The commits should probably be squashed at this point, and verified. |
No .travis.yml for a basic build test? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks about ready to merge to mozilla-services/pushbox master (minus circleci and a deployment setup) let alone rustbox master
token: String, | ||
config: &ServerConfig, | ||
logger: &RBLogger, | ||
) -> request::Outcome<Self, HandlerError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now that this is separate from a request guard, it can return Result instead of Outcome (which can let the error handling code become easier)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not so sure. Both of these are used by from_request
which wants an Outcome
response. I'm sure there's some cleanup that could be done there, but having both of these return Outcome
I think still makes sense.
src/db/models.rs
Outdated
let t_manager = conn.transaction_manager(); | ||
t_manager | ||
.begin_transaction(conn) | ||
.expect("Could not create transaction"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error should never happen, but maybe there's a once in a million db/network hiccup: safer to use .context(HandlerErrorKind::DBError)? instead
src/db/models.rs
Outdated
}; | ||
t_manager | ||
.commit_transaction(conn) | ||
.expect("Could not close transaction"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as begin_transaction
62c955f
to
cc85aab
Compare
This is a rust implementation of PushBox and is a work in progress.
No, travis will be coming shortly, once I iron out the docker stuff. |
This is a rust implementation of PushBox and is a work in progress.