Skip to content

Commit

Permalink
fix(SIte Users): 502 errors for member of lots of organisations (LLC-…
Browse files Browse the repository at this point in the history
…34) (#1513)
  • Loading branch information
PrinceWaune authored Mar 30, 2020
1 parent 6a8e084 commit 18fe639
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/models/plugins/addCRUDFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ async function getConnection({
query.where(cursorFilter);
} else if (before) {
const cursorFilter = paginationToFilter({
cursor: after,
cursor: before,
sort,
paginationDirection: direction
});
Expand Down
44 changes: 35 additions & 9 deletions ui/src/pages/SiteUsersPage/SiteUserOrgItems.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Map } from 'immutable';
import { compose, withProps, setPropTypes } from 'recompose';
import { compose, setPropTypes, withProps } from 'recompose';
import { withModels } from 'ui/utils/hocs';
import SiteUserOrgItem from './SiteUserOrgItem';

Expand All @@ -11,12 +11,12 @@ const enhance = compose(
}),
withProps(({ user }) => {
const schema = 'organisation';
const organisations = user
.get('organisations')
.map(org => new Map({ $oid: org }));
const organisations = user.get('organisations').map(org => new Map({ $oid: org }));
// Decision made via (https://github.com/LearningLocker/learninglocker/pull/1513#issuecomment-587064642)
// Need to change when we will have OrganisationUser model.
const filter = new Map({
_id: new Map({
$in: organisations
$in: organisations.slice(0, 10)
})
});

Expand All @@ -25,11 +25,37 @@ const enhance = compose(
withModels
);

const SiteUserOrgItems = ({ models, user }) => {
const orgsItems = models
.map(org => <SiteUserOrgItem key={org.get('_id').toString()} org={org} user={user} />)
const SiteUserOrgItems = ({ models, user, filter }) => {
// Decision made via (https://github.com/LearningLocker/learninglocker/pull/1513#issuecomment-587064642)
// Need to change when we will have OrganisationUser model.
const orgItems = filter
.get('_id')
.get('$in')
.map((org) => {
const orgModel = models.find(model =>
model.get('_id').toString() === org.get('$oid').toString()
);

if (orgModel === undefined) {
return (
<li key={org.get('$oid').toString()}>
Sorry organisation with id {org.get('$oid')} was deleted!
</li>
);
}

return <SiteUserOrgItem key={orgModel.get('_id').toString()} org={orgModel} user={user} />;
})
.valueSeq();
return <ul>{orgsItems}</ul>;

const countOfRemainingOrganisations = user.get('organisations').count() - orgItems.count();

return (
<div>
<ul>{orgItems}</ul>
{countOfRemainingOrganisations > 0 && <p>Plus { countOfRemainingOrganisations } more not displayed</p>}
</div>
);
};

export default enhance(SiteUserOrgItems);

0 comments on commit 18fe639

Please sign in to comment.