Ignore OrmDuplicateKeyException during PUT .../reviewed
If the reviewed flag has already been set for the calling user return 200 OK instead of throwing a 500 error at the client. This condition can be caused by a race between the getExisting() call and the database write being completed. Change-Id: I1e4c6391cf7e3cfed280dee6abd749fb0934dec0
This commit is contained in:
		| @@ -18,6 +18,7 @@ import com.google.gerrit.extensions.restapi.Response; | ||||
| import com.google.gerrit.extensions.restapi.RestModifyView; | ||||
| import com.google.gerrit.reviewdb.client.AccountPatchReview; | ||||
| import com.google.gerrit.reviewdb.server.ReviewDb; | ||||
| import com.google.gwtorm.server.OrmDuplicateKeyException; | ||||
| import com.google.gwtorm.server.OrmException; | ||||
| import com.google.inject.Inject; | ||||
| import com.google.inject.Provider; | ||||
| @@ -42,9 +43,13 @@ class Reviewed { | ||||
|       ReviewDb db = dbProvider.get(); | ||||
|       AccountPatchReview apr = getExisting(db, resource); | ||||
|       if (apr == null) { | ||||
|         db.accountPatchReviews().insert( | ||||
|             Collections.singleton(new AccountPatchReview(resource.getPatchKey(), | ||||
|                 resource.getAccountId()))); | ||||
|         try { | ||||
|           db.accountPatchReviews().insert( | ||||
|               Collections.singleton(new AccountPatchReview(resource.getPatchKey(), | ||||
|                   resource.getAccountId()))); | ||||
|         } catch (OrmDuplicateKeyException e) { | ||||
|           return Response.ok(""); | ||||
|         } | ||||
|         return Response.created(""); | ||||
|       } else { | ||||
|         return Response.ok(""); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Shawn Pearce
					Shawn Pearce