Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14031922
D16514.id39746.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D16514.id39746.diff
View Options
diff --git a/src/applications/doorkeeper/bridge/DoorkeeperBridge.php b/src/applications/doorkeeper/bridge/DoorkeeperBridge.php
--- a/src/applications/doorkeeper/bridge/DoorkeeperBridge.php
+++ b/src/applications/doorkeeper/bridge/DoorkeeperBridge.php
@@ -48,4 +48,32 @@
return null;
}
+ final protected function saveExternalObject(
+ DoorkeeperObjectRef $ref,
+ DoorkeeperExternalObject $obj) {
+
+ $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
+ try {
+ $obj->save();
+ } catch (AphrontDuplicateKeyQueryException $ex) {
+
+ // In various cases, we may race another process importing the same
+ // data. If we do, we'll collide on the object key. Load the object
+ // the other process created and use that.
+ $obj = id(new DoorkeeperExternalObjectQuery())
+ ->setViewer($this->getViewer())
+ ->withObjectKeys(array($ref->getObjectKey()))
+ ->executeOne();
+ if (!$obj) {
+ throw new PhutilProxyException(
+ pht('Failed to load external object after collision.'),
+ $ex);
+ }
+
+ $ref->attachExternalObject($obj);
+ }
+ unset($unguarded);
+ }
+
+
}
diff --git a/src/applications/doorkeeper/bridge/DoorkeeperBridgeAsana.php b/src/applications/doorkeeper/bridge/DoorkeeperBridgeAsana.php
--- a/src/applications/doorkeeper/bridge/DoorkeeperBridgeAsana.php
+++ b/src/applications/doorkeeper/bridge/DoorkeeperBridgeAsana.php
@@ -113,10 +113,7 @@
}
$this->fillObjectFromData($obj, $result);
-
- $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
- $obj->save();
- unset($unguarded);
+ $this->saveExternalObject($ref, $obj);
}
}
diff --git a/src/applications/doorkeeper/bridge/DoorkeeperBridgeGitHubIssue.php b/src/applications/doorkeeper/bridge/DoorkeeperBridgeGitHubIssue.php
--- a/src/applications/doorkeeper/bridge/DoorkeeperBridgeGitHubIssue.php
+++ b/src/applications/doorkeeper/bridge/DoorkeeperBridgeGitHubIssue.php
@@ -78,10 +78,7 @@
$obj = $ref->getExternalObject();
$this->fillObjectFromData($obj, $result);
-
- $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
- $obj->save();
- unset($unguarded);
+ $this->saveExternalObject($ref, $obj);
}
}
diff --git a/src/applications/doorkeeper/bridge/DoorkeeperBridgeGitHubUser.php b/src/applications/doorkeeper/bridge/DoorkeeperBridgeGitHubUser.php
--- a/src/applications/doorkeeper/bridge/DoorkeeperBridgeGitHubUser.php
+++ b/src/applications/doorkeeper/bridge/DoorkeeperBridgeGitHubUser.php
@@ -101,10 +101,7 @@
$obj = $ref->getExternalObject();
$this->fillObjectFromData($obj, $spec);
-
- $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
- $obj->save();
- unset($unguarded);
+ $this->saveExternalObject($ref, $obj);
}
}
diff --git a/src/applications/doorkeeper/bridge/DoorkeeperBridgeJIRA.php b/src/applications/doorkeeper/bridge/DoorkeeperBridgeJIRA.php
--- a/src/applications/doorkeeper/bridge/DoorkeeperBridgeJIRA.php
+++ b/src/applications/doorkeeper/bridge/DoorkeeperBridgeJIRA.php
@@ -104,10 +104,7 @@
}
$this->fillObjectFromData($obj, $result);
-
- $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
- $obj->save();
- unset($unguarded);
+ $this->saveExternalObject($ref, $obj);
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 10, 12:16 PM (1 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6713523
Default Alt Text
D16514.id39746.diff (3 KB)
Attached To
Mode
D16514: Recover from a race when importing external objects (like JIRA issues) for the first time
Attached
Detach File
Event Timeline
Log In to Comment