Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backend] Improve redis sessions list perf (#7943) #8119

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import ListItem from '@mui/material/ListItem';
import ListItemIcon from '@mui/material/ListItemIcon';
import { DeleteOutlined } from '@mui/icons-material';
import ListItemText from '@mui/material/ListItemText';
import { interval } from 'rxjs';
import Dialog from '@mui/material/Dialog';
import DialogContent from '@mui/material/DialogContent';
import DialogContentText from '@mui/material/DialogContentText';
Expand All @@ -19,21 +18,19 @@ import IconButton from '@mui/material/IconButton';
import { graphql, createRefetchContainer } from 'react-relay';
import inject18n from '../../../components/i18n';
import { commitMutation } from '../../../relay/environment';
import { FIVE_SECONDS, timestamp } from '../../../utils/Time';
import { timestamp } from '../../../utils/Time';
import { userSessionKillMutation } from './users/User';
import ItemIcon from '../../../components/ItemIcon';
import Transition from '../../../components/Transition';
import withRouter from '../../../utils/compat_router/withRouter';

const interval$ = interval(FIVE_SECONDS);

const styles = (theme) => ({
item: {},
itemNested: {
paddingLeft: theme.spacing(4),
},
name: {
width: '20%',
width: '100%',
height: 20,
lineHeight: '20px',
float: 'left',
Expand All @@ -60,6 +57,7 @@ const styles = (theme) => ({
whiteSpace: 'nowrap',
overflow: 'hidden',
textOverflow: 'ellipsis',
fontSize: 12,
},
ttl: {
width: '40%',
Expand Down Expand Up @@ -89,16 +87,6 @@ class SessionsListComponent extends Component {
};
}

componentDidMount() {
this.subscription = interval$.subscribe(() => {
this.props.relay.refetch();
});
}

componentWillUnmount() {
this.subscription.unsubscribe();
}

handleOpenKillSession(session) {
this.setState({ displayKillSession: true, sessionToKill: session });
}
Expand Down Expand Up @@ -163,14 +151,13 @@ class SessionsListComponent extends Component {
</ListItemIcon>
<ListItemText
primary={
<div>
<div className={classes.name}>{user.name}</div>
<div className={classes.email}>{user.email}</div>
<div className={classes.name}>
{user.name} {orderedSessions.length < session.total && (<> - {orderedSessions.length} / {session.total} {t('sessions')}</>)}
</div>
}
/>
<ListItemIcon classes={{ root: classes.goIcon }}>
&nbsp;
&nbsp;
</ListItemIcon>
</ListItem>
<List style={{ margin: 0, padding: 0 }}>
Expand All @@ -187,7 +174,7 @@ class SessionsListComponent extends Component {
primary={
<div>
<div className={classes.created}>
{nsdt(userSession.created)}
{nsdt(userSession.created)} {userSession.user_execution?.name ? (<b>- Impersonating {userSession.user_execution?.name}</b>) : ''}
</div>
<div className={classes.ttl}>
{Math.round(userSession.ttl / 60)}{' '}
Expand Down Expand Up @@ -275,10 +262,14 @@ const SessionsList = createRefetchContainer(
id
name
}
total
sessions {
id
created
ttl
user_execution {
name
}
originalMaxAge
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,12 @@ const UserFragment = graphql`
}
}
sessions {
id
created
ttl
total
sessions {
id
created
ttl
}
}
}
`;
Expand Down Expand Up @@ -335,7 +338,7 @@ const User: FunctionComponent<UserProps> = ({ data, refetch }) => {
},
});
};
const orderedSessions: Session[] = (user.sessions ?? [])
const orderedSessions: Session[] = (user.sessions?.sessions ?? [])
.map((s) => ({
created: s?.created ?? '',
id: s?.id ?? '',
Expand Down Expand Up @@ -559,12 +562,8 @@ const User: FunctionComponent<UserProps> = ({ data, refetch }) => {
</FieldOrEmpty>
</Grid>
<Grid item xs={6}>
<Typography
variant="h3"
gutterBottom={true}
style={{ float: 'left' }}
>
{t_i18n('Sessions')}
<Typography variant="h3" gutterBottom={true} style={{ float: 'left' }}>
{orderedSessions.length < (user.sessions?.total ?? 0) && (<>{t_i18n('Sessions')} - {orderedSessions.length} / {user.sessions?.total}</>)}
</Typography>
<Security needs={[SETTINGS_SETACCESSES]}>
<Tooltip title={t_i18n('Kill all sessions')}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,7 @@ type User implements BasicObject & InternalObject {
objectOrganization(orderBy: OrganizationsOrdering, orderMode: OrderingMode): OrganizationConnection
created_at: DateTime!
updated_at: DateTime!
sessions: [SessionDetail]
sessions: UserSession
default_time_field: String
account_status: String!
account_lock_after_date: DateTime
Expand Down Expand Up @@ -1613,13 +1613,15 @@ type MeUser implements BasicObject & InternalObject {

type SessionDetail {
id: ID!
user_execution: User
created: DateTime
ttl: Int
originalMaxAge: Int
}

type UserSession {
user: Creator
total: Int
sessions: [SessionDetail]
}

Expand Down Expand Up @@ -8375,6 +8377,7 @@ type Mutation {
logout: ID
roleAdd(input: RoleAddInput!): Role
sessionKill(id: ID!): ID
cleanAllSessions: Boolean
userSessionsKill(id: ID!): [ID]
roleEdit(id: ID!): RoleEditMutations
pingConnector(id: ID!, state: String, connectorInfo: ConnectorInfoInput): Connector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,7 @@ type User implements BasicObject & InternalObject {
): OrganizationConnection @auth(for: [SETTINGS_SETACCESSES, VIRTUAL_ORGANIZATION_ADMIN])
created_at: DateTime!
updated_at: DateTime!
sessions: [SessionDetail] @auth(for: [SETTINGS_SETACCESSES, VIRTUAL_ORGANIZATION_ADMIN])
sessions: UserSession @auth(for: [SETTINGS_SETACCESSES, VIRTUAL_ORGANIZATION_ADMIN])
default_time_field: String
account_status: String! @auth(for: [SETTINGS_SETACCESSES, VIRTUAL_ORGANIZATION_ADMIN])
account_lock_after_date: DateTime @auth(for: [SETTINGS_SETACCESSES, VIRTUAL_ORGANIZATION_ADMIN])
Expand Down Expand Up @@ -1546,12 +1546,14 @@ type MeUser implements BasicObject & InternalObject {
}
type SessionDetail {
id: ID!
user_execution: User
created: DateTime
ttl: Int
originalMaxAge: Int
}
type UserSession {
user: Creator
total: Int
sessions: [SessionDetail]
}
input UserAddInput {
Expand Down Expand Up @@ -14023,6 +14025,7 @@ type Mutation {
logout: ID @auth
roleAdd(input: RoleAddInput!): Role @auth(for: [SETTINGS_SETACCESSES])
sessionKill(id: ID!): ID @auth(for: [SETTINGS_SETACCESSES])
cleanAllSessions: Boolean @auth(for: [SETTINGS_SETACCESSES])
userSessionsKill(id: ID!): [ID] @auth(for: [SETTINGS_SETACCESSES])
roleEdit(id: ID!): RoleEditMutations @auth(for: [SETTINGS_SETACCESSES])
pingConnector(id: ID!, state: String, connectorInfo: ConnectorInfoInput): Connector @auth(for: [CONNECTORAPI])
Expand Down
Loading