Skip to content

Commit

Permalink
Fix slow cassandra query. (#1530)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisx authored May 26, 2021
1 parent edf7bb0 commit 7984fcd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
5 changes: 3 additions & 2 deletions services/galley/src/Galley/Data.hs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ import Imports hiding (Set, max)
import System.Logger.Class (MonadLogger)
import qualified System.Logger.Class as Log
import UnliftIO (async, mapConcurrently, wait)
import UnliftIO.Async (pooledMapConcurrentlyN)
import Wire.API.Team.Member

-- We use this newtype to highlight the fact that the 'Page' wrapped in here
Expand Down Expand Up @@ -310,9 +311,9 @@ userTeams u =
map runIdentity
<$> retry x1 (query Cql.selectUserTeams (params Quorum (Identity u)))

usersTeams :: MonadClient m => [UserId] -> m (Map UserId TeamId)
usersTeams :: (MonadUnliftIO m, MonadClient m) => [UserId] -> m (Map UserId TeamId)
usersTeams uids = do
pairs <- retry x1 (query Cql.selectUsersTeams (params Quorum (Identity uids)))
pairs :: [(UserId, TeamId)] <- catMaybes <$> pooledMapConcurrentlyN 8 (\uid -> (uid,) <$$> oneUserTeam uid) uids
pure $ foldl' (\m (k, v) -> Map.insert k v m) Map.empty pairs

oneUserTeam :: MonadClient m => UserId -> m (Maybe TeamId)
Expand Down
3 changes: 0 additions & 3 deletions services/galley/src/Galley/Data/Queries.hs
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ selectUserTeamsIn = "select team from user_team where user = ? and team in ? ord
selectUserTeamsFrom :: PrepQuery R (UserId, TeamId) (Identity TeamId)
selectUserTeamsFrom = "select team from user_team where user = ? and team > ? order by team"

selectUsersTeams :: PrepQuery R (Identity [UserId]) (UserId, TeamId)
selectUsersTeams = "select user, team from user_team where user in ?"

insertTeam :: PrepQuery W (TeamId, UserId, Text, Text, Maybe Text, TeamStatus, TeamBinding) ()
insertTeam = "insert into team (team, creator, name, icon, icon_key, deleted, status, binding) values (?, ?, ?, ?, ?, false, ?, ?)"

Expand Down

0 comments on commit 7984fcd

Please sign in to comment.