@@ -125,29 +125,28 @@ export async function listWorkspacesForViewer(params: {
125125 const { userId, activeOrganizationId, scope = 'active' } = params
126126
127127 /** Workspace pins ride along here; see `pinnedResourceTypeSchema` for why. */
128- const [ creationPolicy , accessibleWorkspaces , userSettings , workspacePins , recentIds ] =
129- await Promise . all ( [
130- getWorkspaceCreationPolicy ( { userId, activeOrganizationId } ) ,
131- listAccessibleWorkspaceRowsForUser ( userId , scope ) . then ( ( rows ) =>
132- buildWorkspacesWithInviteFlags ( rows , userId )
133- ) ,
134- db
135- . select ( { lastActiveWorkspaceId : settings . lastActiveWorkspaceId } )
136- . from ( settings )
137- . where ( eq ( settings . userId , userId ) )
138- . limit ( 1 ) ,
139- db
140- . select ( { resourceId : pinnedItem . resourceId } )
141- . from ( pinnedItem )
142- . where ( and ( eq ( pinnedItem . userId , userId ) , eq ( pinnedItem . resourceType , 'workspace' ) ) ) ,
143- listRecentWorkspaceIds ( userId ) ,
144- ] )
145- const workspaces = sortByVisitRecency ( accessibleWorkspaces , recentIds )
146- const [ mostRecent ] = workspaces
128+ const [ creationPolicy , workspaces , userSettings , workspacePins , recentIds ] = await Promise . all ( [
129+ getWorkspaceCreationPolicy ( { userId, activeOrganizationId } ) ,
130+ listAccessibleWorkspaceRowsForUser ( userId , scope ) . then ( ( rows ) =>
131+ buildWorkspacesWithInviteFlags ( rows , userId )
132+ ) ,
133+ db
134+ . select ( { lastActiveWorkspaceId : settings . lastActiveWorkspaceId } )
135+ . from ( settings )
136+ . where ( eq ( settings . userId , userId ) )
137+ . limit ( 1 ) ,
138+ db
139+ . select ( { resourceId : pinnedItem . resourceId } )
140+ . from ( pinnedItem )
141+ . where ( and ( eq ( pinnedItem . userId , userId ) , eq ( pinnedItem . resourceType , 'workspace' ) ) ) ,
142+ listRecentWorkspaceIds ( userId ) ,
143+ ] )
144+ const orderedWorkspaces = sortByVisitRecency ( workspaces , recentIds )
145+ const [ mostRecent ] = orderedWorkspaces
147146 const lastVisitedId = mostRecent && recentIds . includes ( mostRecent . id ) ? mostRecent . id : null
148147
149148 return {
150- workspaces,
149+ workspaces : orderedWorkspaces ,
151150 /** Visits supersede the settings column, which only predates them. */
152151 lastActiveWorkspaceId : lastVisitedId ?? userSettings [ 0 ] ?. lastActiveWorkspaceId ?? null ,
153152 pinnedWorkspaceIds : workspacePins . map ( ( row ) => row . resourceId ) ,
0 commit comments