Skip to content

Commit

Permalink
[SDAAP-51] Populating the completed assignments list on the assignmen…
Browse files Browse the repository at this point in the history
…ts page is slow (#1746)
  • Loading branch information
marwoodandrew authored and MarkLark86 committed Dec 15, 2022
1 parent 4646eff commit e1e23d6
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 14 deletions.
2 changes: 2 additions & 0 deletions client/actions/assignments/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ const query = ({
dateFilter = null,
size = null,
ignoreScheduledUpdates = false,
max_results = null,
}) => (
(dispatch, getState, {api}) => {
const filterByValues = {
Expand Down Expand Up @@ -190,6 +191,7 @@ const query = ({

return api('assignments').query({
page: page,
max_results: max_results,
sort: sort,
source: JSON.stringify(size !== null ?
{query, size} :
Expand Down
9 changes: 9 additions & 0 deletions client/actions/assignments/tests/api_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ describe('actions.assignments.api', () => {
page: 2,
sort: '[("_created", 1)]',
source: source,
max_results: null,
});

done();
Expand Down Expand Up @@ -180,6 +181,7 @@ describe('actions.assignments.api', () => {
page: 3,
sort: '[("_updated", -1)]',
source: source,
max_results: null,
});

done();
Expand Down Expand Up @@ -208,6 +210,7 @@ describe('actions.assignments.api', () => {
page: 3,
sort: '[("_updated", -1)]',
source: source,
max_results: null
});

done();
Expand Down Expand Up @@ -236,6 +239,7 @@ describe('actions.assignments.api', () => {
page: 3,
sort: '[("_updated", -1)]',
source: source,
max_results: null,
});

done();
Expand Down Expand Up @@ -263,6 +267,7 @@ describe('actions.assignments.api', () => {
page: 3,
sort: '[("_updated", -1)]',
source: source,
max_results: null,
});

done();
Expand Down Expand Up @@ -290,6 +295,7 @@ describe('actions.assignments.api', () => {
page: 3,
sort: '[("priority", -1)]',
source: source,
max_results: null,
});

done();
Expand Down Expand Up @@ -317,6 +323,7 @@ describe('actions.assignments.api', () => {
page: 3,
sort: '[("priority", 1)]',
source: source,
max_results: null,
});

done();
Expand Down Expand Up @@ -371,6 +378,7 @@ describe('actions.assignments.api', () => {
page: 1,
sort: '[("priority", 1)]',
source: source,
max_results: null,
});

done();
Expand Down Expand Up @@ -399,6 +407,7 @@ describe('actions.assignments.api', () => {
page: 1,
sort: '[("_updated", -1)]',
source: source,
max_results: null,
});

done();
Expand Down
1 change: 1 addition & 0 deletions client/actions/assignments/tests/ui_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ describe('actions.assignments.ui', () => {
type: null,
priority: null,
ignoreScheduledUpdates: false,
max_results: 100,
}]);

expect(assignmentsApi.receivedAssignments.callCount).toBe(1);
Expand Down
3 changes: 3 additions & 0 deletions client/actions/assignments/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ const queryAndSetAssignmentListGroups = (groupKey, page = 1) => (
querySearchSettings.page = page;
querySearchSettings.dateFilter = group.dateFilter;
querySearchSettings.orderDirection = assignmentListSelectors.sortOrder(getState());
if (group.max_results) {
querySearchSettings.max_results = group.max_results;
}

return dispatch(assignments.api.query(querySearchSettings))
.then((data) => {
Expand Down
3 changes: 3 additions & 0 deletions client/constants/assignments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,21 @@ export const ASSIGNMENTS = {
id: 'TODO',
label: 'To Do',
states: ['assigned', 'submitted'],
max_results: 100,
emptyMessage: 'There are no assignments to do',
},
IN_PROGRESS: {
id: 'IN_PROGRESS',
label: 'In Progress',
states: ['in_progress'],
max_results: 100,
emptyMessage: 'There are no assignments in progress',
},
COMPLETED: {
id: 'COMPLETED',
label: 'Completed',
states: ['completed', 'cancelled'],
max_results: 100,
emptyMessage: 'There are no assignments completed',
},
CURRENT: {
Expand Down
42 changes: 28 additions & 14 deletions server/planning/assignments/assignments.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,29 +85,43 @@ def on_fetched_item_archive(self, doc):

def _enhance_archive_items(self, docs):
ids = [str(item["assignment_id"]) for item in docs if item.get("assignment_id")]
assignments = {
str(item[config.ID_FIELD]): item for item in self.get_from_mongo(req=None, lookup={"_id": {"$in": ids}})
}
if len(ids):
assignments = {
str(item[config.ID_FIELD]): item for item in self.get_from_mongo(req=None, lookup={"_id": {"$in": ids}})
}

for doc in docs:
if doc.get("assignment_id") in assignments:
doc["assignment"] = assignments[doc["assignment_id"]].get("assigned_to") or {}
for doc in docs:
if doc.get("assignment_id") in assignments:
doc["assignment"] = assignments[doc["assignment_id"]].get("assigned_to") or {}

def on_fetched(self, docs):
for doc in docs["_items"]:
self._enchance_assignment(doc)
self._enhance_assignments(docs.get("_items", []))

def on_fetched_item(self, doc):
self._enchance_assignment(doc)
self._enhance_assignments([doc])

def _enchance_assignment(self, doc):
def _enhance_assignments(self, docs):
"""Populate `item_ids` with ids for all linked Archive items for an Assignment"""
items = list(self.get_archive_items_for_assignments([str(doc.get(config.ID_FIELD)) for doc in docs]))
for doc in docs:
ids = [str(item.get("_id")) for item in items if str(item.get("assignment_id")) == str(doc.get("_id"))]
if len(ids):
doc["item_ids"] = ids

self.set_type(doc, doc)

results = self.get_archive_items_for_assignment(doc)
if results.count() > 0:
doc["item_ids"] = [str(item.get(config.ID_FIELD)) for item in results]
def get_archive_items_for_assignments(self, assignment_ids):
"""
Given an array of assignment id's return the matching items
:param assignment_ids:
:return:
"""
query = {"query": {"filtered": {"filter": {"terms": {"assignment_id": assignment_ids}}}}}

self.set_type(doc, doc)
req = ParsedRequest()
repos = "archive,published,archived"
req.args = {"source": json.dumps(query), "repo": repos}
return get_resource_service("search").get(req=req, lookup=None)

def get_archive_items_for_assignment(self, assignment):
"""Using the `search` resource service, retrieve the list of Archive items linked to the provided Assignment."""
Expand Down

0 comments on commit e1e23d6

Please sign in to comment.