api: retry twice for insert

This commit is contained in:
Peter Cai 2020-02-21 16:25:57 +08:00
parent bcde7ca74a
commit fd9b1310b0
No known key found for this signature in database
GPG Key ID: 71F5FB4E4F3FD54F
1 changed files with 9 additions and 4 deletions

View File

@ -174,10 +174,15 @@ fn items_sync(db: DbConn, u: user::User, params: Json<SyncParams>) -> Custom<Jso
// First, update all items sent by client
for it in inner_params.items.into_iter() {
if let Err(item::ItemOpError(_)) = item::SyncItem::items_insert(&db, &u, &it) {
// Let's not fail just because one of them...
// At least the client will know there's an error
// (maybe mistakes it for conflict)
resp.unsaved.push(it);
// Well, we should try twice...
// TODO: make this more elegant (also handle differneces between db error and conflict)
// (if we were ever to implement a conflict feature)
if let Err(item::ItemOpError(_)) = item::SyncItem::items_insert(&db, &u, &it) {
// Let's not fail just because one of them...
// At least the client will know there's an error
// (maybe mistakes it for conflict)
resp.unsaved.push(it);
}
} else {
resp.saved_items.push(it);
}