Skip to content

Commit

Permalink
Fix cassandra query. (#3508)
Browse files Browse the repository at this point in the history
* Fix cassandra query.

* Changelog.

* Add missing internal route ID.
  • Loading branch information
fisx authored Aug 16, 2023
1 parent e4d8a78 commit 652c2b8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions changelog.d/3-bug-fixes/wpd-3888
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix syntax error in cassandra update to `brig.client`.
15 changes: 9 additions & 6 deletions libs/wire-api/src/Wire/API/Routes/Internal/Brig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -694,12 +694,15 @@ type GetDefaultLocale =
:> Get '[Servant.JSON] LocaleUpdate

type ClientAPI =
Summary "Update last_active field of a client"
:> "clients"
:> Capture "uid" UserId
:> Capture "client" ClientId
:> "activity"
:> MultiVerb1 'POST '[Servant.JSON] (RespondEmpty 200 "OK")
Named
"update-client-last-active"
( Summary "Update last_active field of a client"
:> "clients"
:> Capture "uid" UserId
:> Capture "client" ClientId
:> "activity"
:> MultiVerb1 'POST '[Servant.JSON] (RespondEmpty 200 "OK")
)

type AuthAPI =
Named
Expand Down
2 changes: 1 addition & 1 deletion services/brig/src/Brig/API/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ userAPI =
:<|> getDefaultUserLocale

clientAPI :: ServerT BrigIRoutes.ClientAPI (Handler r)
clientAPI = updateClientLastActive
clientAPI = Named @"update-client-last-active" updateClientLastActive

authAPI :: (Member GalleyProvider r) => ServerT BrigIRoutes.AuthAPI (Handler r)
authAPI =
Expand Down
7 changes: 4 additions & 3 deletions services/brig/src/Brig/Data/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,11 @@ updateClientLabel u c l = retry x5 $ write updateClientLabelQuery (params LocalQ
updateClientCapabilities :: MonadClient m => UserId -> ClientId -> Maybe (Imports.Set ClientCapability) -> m ()
updateClientCapabilities u c fs = retry x5 $ write updateClientCapabilitiesQuery (params LocalQuorum (C.Set . Set.toList <$> fs, u, c))

-- | If the update fails, which can happen if device does not exist, then ignore the error silently.
updateClientLastActive :: MonadClient m => UserId -> ClientId -> UTCTime -> m ()
updateClientLastActive u c t =
retry x5 $
write
void . retry x5 $
trans
updateClientLastActiveQuery
(params LocalQuorum (t, u, c))

Expand Down Expand Up @@ -386,7 +387,7 @@ updateClientLabelQuery = "UPDATE clients SET label = ? WHERE user = ? AND client
updateClientCapabilitiesQuery :: PrepQuery W (Maybe (C.Set ClientCapability), UserId, ClientId) ()
updateClientCapabilitiesQuery = "UPDATE clients SET capabilities = ? WHERE user = ? AND client = ?"

updateClientLastActiveQuery :: PrepQuery W (UTCTime, UserId, ClientId) ()
updateClientLastActiveQuery :: PrepQuery W (UTCTime, UserId, ClientId) Row
updateClientLastActiveQuery = "UPDATE clients SET last_active = ? WHERE user = ? AND client = ? IF EXISTS"

selectClientIds :: PrepQuery R (Identity UserId) (Identity ClientId)
Expand Down
2 changes: 1 addition & 1 deletion services/brig/src/Brig/Data/MLS/KeyPackage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ keyPackageRefSetConvId ref convId = do
[_] -> pure True
_ -> throwM $ ErrorCall "Primary key violation detected mls_key_package_refs.ref"
where
q :: PrepQuery W (Domain, ConvId, KeyPackageRef) x
q :: PrepQuery W (Domain, ConvId, KeyPackageRef) Row
q = "UPDATE mls_key_package_refs SET conv_domain = ?, conv = ? WHERE ref = ? IF EXISTS"

addKeyPackageRef :: MonadClient m => KeyPackageRef -> NewKeyPackageRef -> m ()
Expand Down

0 comments on commit 652c2b8

Please sign in to comment.