Skip to content

Commit

Permalink
#492 Removed latest contributions from most pages to reduce db load
Browse files Browse the repository at this point in the history
  • Loading branch information
cdausmus committed Jan 27, 2022
1 parent 864c0f7 commit f4ad9b1
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 27 deletions.
34 changes: 19 additions & 15 deletions grails-app/assets/javascripts/digivol-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,26 @@ function digivolStats(config) {
$log.error("Got error response for leaderboard", resp);
});

var c = $http.get(config.contributorsUrl, {
params: {
institutionId: config.institutionId,
projectId: config.projectId,
projectType: config.projectType,
tags: config.tags,
maxContributors: config.maxContributors
}
});
c.then(function (resp) {
angular.extend($scope, resp.data);
$scope.conLoading = false;
},
function (resp) {
$log.error("Got error response for contributors", resp);
//console.log("Disable contributors: " + config.disableContribution);
if (config.disableContribution === false) {
console.log("Getting contributors");
var c = $http.get(config.contributorsUrl, {
params: {
institutionId: config.institutionId,
projectId: config.projectId,
projectType: config.projectType,
tags: config.tags,
maxContributors: config.maxContributors
}
});
c.then(function (resp) {
angular.extend($scope, resp.data);
$scope.conLoading = false;
},
function (resp) {
$log.error("Got error response for contributors", resp);
});
}
}
]);
}
Expand Down
2 changes: 2 additions & 0 deletions grails-app/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ default.button.approve.label=Approve
default.button.delete.label=Delete
default.button.delete.confirm.message=Are you sure?

default.leaderboard.describeBadges.label=Badges

# Data binding errors. Use "typeMismatch.$className.$propertyName to customize (eg typeMismatch.Book.author)
typeMismatch.java.net.URL=Property {0} must be a valid URL
typeMismatch.java.net.URI=Property {0} must be a valid URI
Expand Down
2 changes: 1 addition & 1 deletion grails-app/views/about.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@

</div>
<div class="col-sm-4">
<g:render template="/leaderBoard/stats" model="[disableStats: true]"/>
<g:render template="/leaderBoard/stats" model="[disableStats: true, disableContribution: true]"/>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion grails-app/views/institution/index.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@

</div>
<div class="col-sm-4">
<g:render template="/leaderBoard/stats"/>
<g:render template="/leaderBoard/stats" model="[disableContribution: true]"/>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion grails-app/views/institution/list.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
</div><!-- /.col-sm-8 -->

<div class="col-sm-4">
<g:render template="/leaderBoard/stats"/>
<g:render template="/leaderBoard/stats" model="[disableContribution: true]"/>
</div>
</div>
</div>
Expand Down
14 changes: 10 additions & 4 deletions grails-app/views/leaderBoard/_stats.gsp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
%{-- include CSS and JS assets in calling page --}%
<g:set var="instName" value="${institutionName ?: institutionInstance?.name ?: message(code: 'default.application.name')}"/>
<g:set var="institutionId" value="${institutionInstance?.id}"/>


<section id="digivol-stats" ng-app="stats" ng-controller="StatsCtrl" class="ng-cloak">
<g:if test="${!disableStats}">
<g:if test="${!disableStats}">
<div class="panel panel-default volunteer-stats">
<!-- Default panel contents -->
<h2 class="heading">${instName} Stats
Expand All @@ -25,8 +27,8 @@
</p>

</div><!-- Volunteer Stats Ends Here -->
</g:if>
<g:if test="${!disableHonourBoard}">
</g:if>
<g:if test="${!disableHonourBoard}">
<div class="panel panel-default leaderboard">
<!-- Default panel contents -->
<h2 class="heading"><g:message code="honour.board.label" /> <g:link controller="leaderBoard" action="describeBadges" class="pull-right"><i class="fa fa-trophy fa-sm"></i></g:link></h2>
Expand Down Expand Up @@ -128,8 +130,9 @@
</tbody>
</table>
</div><!-- Honour Board Ends Here -->
</g:if>
</g:if>

<g:if test="${!disableContribution}">
<h2 class="heading">
<g:message code="latest.contributions.label" /><span data-ng-if="conLoading"> <cl:spinner/></span>
</h2>
Expand Down Expand Up @@ -177,8 +180,10 @@
</div>
</li>
</ul>
</g:if>

</section>

<asset:javascript src="digivol-stats.js" asset-defer=""/>
<asset:script type="text/javascript">
digivolStats({
Expand All @@ -194,5 +199,6 @@ digivolStats({
maxContributors: ${maxContributors ?: 5},
disableStats: ${disableStats ? 'true' : 'false' },
disableHonourBoard: ${disableHonourBoard ? 'true' : 'false' },
disableContribution: ${disableContribution ? 'true' : 'false' }
});
</asset:script>
2 changes: 1 addition & 1 deletion grails-app/views/leaderBoard/describeBadges.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</div>
</div>
<div class="col-sm-4">
<g:render template="/leaderBoard/stats" model="[disableStats: true]"/>
<g:render template="/leaderBoard/stats" model="[disableStats: true, disableContribution: true]"/>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion grails-app/views/project/customLandingPage.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
</div>
<div class="col-sm-4">
%{--<g:set var="model" value="${[institutionName: 'Wildlife Spotter', projectType: projectType, tagName, tags]}" />--}%
<g:render template="/leaderBoard/stats" model="[institutionName: landingPageInstance.title, tagName: tags, projectType: projectType]" />
<g:render template="/leaderBoard/stats" model="[institutionName: landingPageInstance.title, tagName: tags, projectType: projectType, disableContribution: true]" />
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion grails-app/views/project/index.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
<div class="col-sm-4">
%{-- mini leaderboard --}%
<g:render template="/leaderBoard/stats" model="[disableStats: true, disableHonourBoard: true, projectId: projectInstance.id, maxContributors: 2]"/>
<g:render template="/leaderBoard/stats" model="[disableStats: true, disableHonourBoard: true, disableContribution: true, projectId: projectInstance.id, maxContributors: 2]"/>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion grails-app/views/project/list.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
</g:else>
</div>
<div class="col-sm-4">
<g:render template="/leaderBoard/stats"/>
<g:render template="/leaderBoard/stats" model="[disableContribution: true]"/>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion grails-app/views/project/wildlifespotter.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
</g:else>
</div>
<div class="col-sm-4">
<g:render template="/leaderBoard/stats" model="[institutionName: 'Wildlife Spotter', tagName: ProjectType.PROJECT_TYPE_CAMERATRAP]"/>
<g:render template="/leaderBoard/stats" model="[disableContribution: true, institutionName: 'Wildlife Spotter', tagName: ProjectType.PROJECT_TYPE_CAMERATRAP]"/>
</div>
</div>
</div>
Expand Down

0 comments on commit f4ad9b1

Please sign in to comment.