@@ -61,9 +61,7 @@ export const getCommunitiesByUser = (userId: string): Promise<Array<DBCommunity>
6161 db
6262 . table ( 'usersCommunities' )
6363 // get all the user's communities
64- . getAll ( userId , { index : 'userId' } )
65- // only return communities the user is a member of
66- . filter ( { isMember : true } )
64+ . getAll ( [ userId , true ] , { index : 'userIdAndIsMember' } )
6765 // get the community objects for each community
6866 . eqJoin ( 'communityId' , db . table ( 'communities' ) )
6967 // get rid of unnecessary info from the usersCommunities object on the left
@@ -81,9 +79,7 @@ export const getVisibleCommunitiesByUser = async (evaluatingUserId: string, curr
8179 const evaluatingUserMemberships = await db
8280 . table ( 'usersCommunities' )
8381 // get all the user's communities
84- . getAll ( evaluatingUserId , { index : 'userId' } )
85- // only return communities the user is a member of
86- . filter ( { isMember : true } )
82+ . getAll ( [ evaluatingUserId , true ] , { index : 'userIdAndIsMember' } )
8783 // get the community objects for each community
8884 . eqJoin ( 'communityId' , db . table ( 'communities' ) )
8985 // get rid of unnecessary info from the usersCommunities object on the left
@@ -97,9 +93,7 @@ export const getVisibleCommunitiesByUser = async (evaluatingUserId: string, curr
9793 const currentUserMemberships = await db
9894 . table ( 'usersCommunities' )
9995 // get all the user's communities
100- . getAll ( currentUserId , { index : 'userId' } )
101- // only return communities the user is a member of
102- . filter ( { isMember : true } )
96+ . getAll ( [ currentUserId , true ] , { index : 'userIdAndIsMember' } )
10397 // get the community objects for each community
10498 . eqJoin ( 'communityId' , db . table ( 'communities' ) )
10599 // get rid of unnecessary info from the usersCommunities object on the left
@@ -130,9 +124,7 @@ export const getPublicCommunitiesByUser = async (userId: string) => {
130124 return await db
131125 . table ( 'usersCommunities' )
132126 // get all the user's communities
133- . getAll ( userId , { index : 'userId' } )
134- // only return communities the user is a member of
135- . filter ( { isMember : true } )
127+ . getAll ( [ userId , true ] , { index : 'userIdAndIsMember' } )
136128 // get the community objects for each community
137129 . eqJoin ( 'communityId' , db . table ( 'communities' ) )
138130 // only return public community ids
@@ -159,8 +151,9 @@ export const getCommunitiesChannelCounts = (communityIds: Array<string>) => {
159151export const getCommunitiesMemberCounts = ( communityIds : Array < string > ) => {
160152 return db
161153 . table ( 'usersCommunities' )
162- . getAll ( ...communityIds , { index : 'communityId' } )
163- . filter ( { isBlocked : false , isMember : true } )
154+ . getAll ( ...communityIds . map ( id => [ id , true ] ) , {
155+ index : 'communityIdAndIsMember' ,
156+ } )
164157 . group ( 'communityId' )
165158 . count ( )
166159 . run ( ) ;
@@ -171,10 +164,9 @@ export const getCommunitiesOnlineMemberCounts = (
171164) => {
172165 return db
173166 . table ( 'usersCommunities' )
174- . getAll ( ...communityIds , {
175- index : 'communityId ' ,
167+ . getAll ( ...communityIds . map ( id => [ id , true ] ) , {
168+ index : 'communityIdAndIsMember ' ,
176169 } )
177- . filter ( { isBlocked : false , isMember : true } )
178170 . pluck ( [ 'communityId' , 'userId' ] )
179171 . eqJoin ( 'userId' , db . table ( 'users' ) )
180172 . pluck ( 'left' , { right : [ 'lastSeen' , 'isOnline' ] } )
@@ -812,8 +804,7 @@ export const setMemberCount = (
812804export const getMemberCount = ( communityId : string ) : Promise < number > => {
813805 return db
814806 . table ( 'usersCommunities' )
815- . getAll ( communityId , { index : 'communityId' } )
816- . filter ( { isMember : true } )
807+ . getAll ( [ communityId , true ] , { index : 'communityIdAndIsMember' } )
817808 . count ( )
818809 . run ( ) ;
819810} ;
0 commit comments