From b0da8747a2bd69b2a21e4690e65a1b9b9fde3d6c Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Tue, 16 Apr 2019 16:33:08 +0000 Subject: [PATCH] In ActorFetchShare, use insertBy' to allow non-shared insertions Before this patch, the shared fetch used plain insert, because it relied on being the only place in the codebase where new RemoteActors get inserted. I was hoping for that to be the case, but while I tweak things and handle fetching URIs that can be an actor or a public key (for which ActorFetchShare isn't sufficient without some smart modification), I'd like concurrent insertions to be safe, without getting in the way of ActorFetchShare. With this patch, it now uses insertBy', which doesn't mind concurrent insertions. --- src/Vervis/RemoteActorStore.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Vervis/RemoteActorStore.hs b/src/Vervis/RemoteActorStore.hs index 8833607..4dd0d66 100644 --- a/src/Vervis/RemoteActorStore.hs +++ b/src/Vervis/RemoteActorStore.hs @@ -451,8 +451,7 @@ addVerifKey h uinb vkd = actorFetchShareSettings :: ( YesodPersist site - , PersistUniqueRead (YesodPersistBackend site) - , PersistStoreWrite (YesodPersistBackend site) + , PersistUniqueWrite (YesodPersistBackend site) , BaseBackend (YesodPersistBackend site) ~ SqlBackend , HasHttpManager site ) @@ -468,7 +467,8 @@ actorFetchShareSettings = ResultShareSettings manager <- getsYesod getHttpManager eactor <- fetchAPID' manager actorId h lu for eactor $ \ actor -> runDB $ - insertEntity $ RemoteActor lu iid (actorInbox actor) Nothing + let ra = RemoteActor lu iid (actorInbox actor) Nothing + in either id (flip Entity ra) <$> insertBy' ra } fetchRemoteActor