Skip to content
Snippets Groups Projects
Commit db3abe6b authored by srosse's avatar srosse
Browse files

OO-984: if rating and comment is disabled, don't join fetch the repository statistics

parent 77001a21
No related branches found
No related tags found
No related merge requests found
...@@ -47,6 +47,7 @@ import org.olat.repository.RepositoryEntry; ...@@ -47,6 +47,7 @@ import org.olat.repository.RepositoryEntry;
import org.olat.repository.RepositoryEntryMyView; import org.olat.repository.RepositoryEntryMyView;
import org.olat.repository.RepositoryModule; import org.olat.repository.RepositoryModule;
import org.olat.repository.model.RepositoryEntryMyCourseImpl; import org.olat.repository.model.RepositoryEntryMyCourseImpl;
import org.olat.repository.model.RepositoryEntryStatistics;
import org.olat.repository.model.SearchMyRepositoryEntryViewParams; import org.olat.repository.model.SearchMyRepositoryEntryViewParams;
import org.olat.repository.model.SearchMyRepositoryEntryViewParams.Filter; import org.olat.repository.model.SearchMyRepositoryEntryViewParams.Filter;
import org.olat.repository.model.SearchMyRepositoryEntryViewParams.OrderBy; import org.olat.repository.model.SearchMyRepositoryEntryViewParams.OrderBy;
...@@ -103,6 +104,8 @@ public class RepositoryEntryMyCourseQueries { ...@@ -103,6 +104,8 @@ public class RepositoryEntryMyCourseQueries {
query.setMaxResults(maxResults); query.setMaxResults(maxResults);
} }
boolean neddStats = repositoryModule.isRatingEnabled() || repositoryModule.isCommentEnabled();
List<Long> effKeys = new ArrayList<>(); List<Long> effKeys = new ArrayList<>();
List<Object[]> objects = query.getResultList(); List<Object[]> objects = query.getResultList();
List<RepositoryEntryMyView> views = new ArrayList<>(objects.size()); List<RepositoryEntryMyView> views = new ArrayList<>(objects.size());
...@@ -115,7 +118,13 @@ public class RepositoryEntryMyCourseQueries { ...@@ -115,7 +118,13 @@ public class RepositoryEntryMyCourseQueries {
long offers = numOffers == null ? 0l : numOffers.longValue(); long offers = numOffers == null ? 0l : numOffers.longValue();
Integer myRating = (Integer)object[3]; Integer myRating = (Integer)object[3];
RepositoryEntryMyCourseImpl view = new RepositoryEntryMyCourseImpl(re, hasMarks, offers, myRating); RepositoryEntryStatistics stats;
if(neddStats) {
stats = re.getStatistics();
} else {
stats = null;
}
RepositoryEntryMyCourseImpl view = new RepositoryEntryMyCourseImpl(re, stats, hasMarks, offers, myRating);
views.add(view); views.add(view);
viewsMap.put(re.getOlatResource(), view); viewsMap.put(re.getOlatResource(), view);
...@@ -157,7 +166,6 @@ public class RepositoryEntryMyCourseQueries { ...@@ -157,7 +166,6 @@ public class RepositoryEntryMyCourseQueries {
sb.append("select count(v.key) ") sb.append("select count(v.key) ")
.append(" from repositoryentry as v, ").append(IdentityImpl.class.getName()).append(" as ident ") .append(" from repositoryentry as v, ").append(IdentityImpl.class.getName()).append(" as ident ")
.append(" inner join v.olatResource as res") .append(" inner join v.olatResource as res")
.append(" inner join v.statistics as stats")
.append(" left join v.lifecycle as lifecycle "); .append(" left join v.lifecycle as lifecycle ");
} else { } else {
sb.append("select v, ") sb.append("select v, ")
...@@ -185,9 +193,11 @@ public class RepositoryEntryMyCourseQueries { ...@@ -185,9 +193,11 @@ public class RepositoryEntryMyCourseQueries {
.append(" ) as effKey"); .append(" ) as effKey");
appendOrderByInSelect(params, sb); appendOrderByInSelect(params, sb);
sb.append(" from repositoryentry as v, ").append(IdentityImpl.class.getName()).append(" as ident ") sb.append(" from repositoryentry as v, ").append(IdentityImpl.class.getName()).append(" as ident ")
.append(" inner join ").append(oracle ? "" : "fetch").append(" v.olatResource as res") .append(" inner join ").append(oracle ? "" : "fetch").append(" v.olatResource as res");
.append(" inner join fetch v.statistics as stats") if(repositoryModule.isRatingEnabled() || repositoryModule.isCommentEnabled()) {
.append(" left join fetch v.lifecycle as lifecycle "); sb.append(" inner join fetch v.statistics as stats");
}
sb.append(" left join fetch v.lifecycle as lifecycle ");
} }
//user course informations //user course informations
//efficiency statements //efficiency statements
......
...@@ -67,7 +67,7 @@ public class RepositoryEntryMyCourseImpl implements RepositoryEntryMyView, Creat ...@@ -67,7 +67,7 @@ public class RepositoryEntryMyCourseImpl implements RepositoryEntryMyView, Creat
private long offersAvailable; private long offersAvailable;
public RepositoryEntryMyCourseImpl(RepositoryEntry re, public RepositoryEntryMyCourseImpl(RepositoryEntry re, RepositoryEntryStatistics stats,
boolean marked, long offersAvailable, Integer myRating) { boolean marked, long offersAvailable, Integer myRating) {
key = re.getKey(); key = re.getKey();
externalRef = re.getExternalRef(); externalRef = re.getExternalRef();
...@@ -85,8 +85,7 @@ public class RepositoryEntryMyCourseImpl implements RepositoryEntryMyView, Creat ...@@ -85,8 +85,7 @@ public class RepositoryEntryMyCourseImpl implements RepositoryEntryMyView, Creat
this.marked = marked; this.marked = marked;
this.myRating = myRating; this.myRating = myRating;
RepositoryEntryStatistics stats = re.getStatistics();
if(stats != null) { if(stats != null) {
averageRating = stats.getRating(); averageRating = stats.getRating();
numOfRatings = stats.getNumOfRatings(); numOfRatings = stats.getNumOfRatings();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment