Skip to content

Commit

Permalink
Query activities separately only when needed on project page load #3453
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Feb 20, 2025
1 parent 333ef2e commit 742a496
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class ProjectController {
user.isEditor = projectService.canUserEditProject(user.userId, id) ?: false
user.hasViewAccess = projectService.canUserViewProject(user.userId, id) ?: false
}
def project = projectService.get(id, user,'all')
def project = projectService.get(id, user)
Map config = null
if (project && !project.error) {
config = projectService.getProgramConfiguration(project)
Expand Down Expand Up @@ -213,11 +213,13 @@ class ProjectController {
if (template == MERI_ONLY_TEMPLATE) {
model = [details:model.details]
}
else if (!template || template == ProgramConfig.ProjectTemplate.DEFAULT.name()) {
project.activities = activityService.activitiesForProject(project.projectId)
}
else if (template == RLP_TEMPLATE) {

// The RLP Project Template doesn't need site details or activities.
project.sites = new JSONArray(project.sites?.collect{new JSONObject([name:it.name, siteId:it.siteId, lastUpdated:it.lastUpdated, type:it.type, extent:[:], publicationStatus:it.publicationStatus, externalIds:it.externalIds])} ?: [])
project.remove('activities')

model.details.meriPlanTemplate = config.meriPlanTemplate ? config.meriPlanTemplate+"View" : RLP_MERI_PLAN_TEMPLATE+'View'

Expand Down
19 changes: 11 additions & 8 deletions grails-app/services/au/org/ala/merit/ProjectService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,18 @@ class ProjectService {

params += levelOfDetail ? "view=${levelOfDetail}&" : ''
params += "includeDeleted=${includeDeleted}"
Map project = webService.getJson(grailsApplication.config.getProperty('ecodata.baseUrl') + 'project/' + id + params)
if (!project.reports) {
project.reports = reportService.getReportsForProject(id)
}
else {
project.reports.sort ({ it.toDate })
}
project
Map resp = webService.getJson2(grailsApplication.config.getProperty('ecodata.baseUrl') + 'project/' + id + params, 1000000)
if (resp?.statusCode == HttpStatus.SC_OK) {
Map project = resp.resp

if (!project.reports) {
project.reports = reportService.getReportsForProject(id)
} else {
project.reports.sort({ it.toDate })
}
return project
}
return resp
}

Map findStateAndElectorateForProject(String projectId) {
Expand Down

0 comments on commit 742a496

Please sign in to comment.