From 22bd91b456e4f4dc1d39391a8615e3039e776fb0 Mon Sep 17 00:00:00 2001 From: srosse <none@none> Date: Fri, 22 Aug 2014 14:59:12 +0200 Subject: [PATCH] OO-984: reduce number of queries in repository details and runtime, optimize contact list for chat --- .../olat/core/servlets/OpenOLATServlet.java | 6 +++--- .../org/olat/group/manager/ContactDAO.java | 5 ++--- .../olat/repository/RepositoryService.java | 6 ++++++ .../RepositoryEntryMyCourseQueries.java | 14 ++++++++----- .../model/RepositoryEntrySecurity.java | 4 ++++ .../ui/RepositoryEntryRuntimeController.java | 2 +- .../RepositoryEntryDetailsController.java | 19 ++++++++++------- .../repository/ui/list/_content/details.html | 3 ++- .../resource/accesscontrol/ACService.java | 10 +++++++++ .../manager/ACFrontendManager.java | 21 +++++++++++++++++-- 10 files changed, 68 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/olat/core/servlets/OpenOLATServlet.java b/src/main/java/org/olat/core/servlets/OpenOLATServlet.java index ff6f1cbd371..dd475c93817 100644 --- a/src/main/java/org/olat/core/servlets/OpenOLATServlet.java +++ b/src/main/java/org/olat/core/servlets/OpenOLATServlet.java @@ -65,7 +65,7 @@ public class OpenOLATServlet extends HttpServlet { private String legacyContext; - private DispatcherModule dispatcher; + private DispatcherModule dispatcherModule; private SessionStatsManager sessionStatsManager; private RequestBasedLogLevelManager requestBasedLogLevelManager; @@ -96,9 +96,9 @@ public class OpenOLATServlet extends HttpServlet { FrameworkStartupEventChannel.fireEvent(); log.info("FrameworkStartupEvent processed by alle listeners. Webapp has started."); sessionStatsManager = CoreSpringFactory.getImpl(SessionStatsManager.class); - dispatcher = CoreSpringFactory.getImpl(DispatcherModule.class); + dispatcherModule = CoreSpringFactory.getImpl(DispatcherModule.class); - dispatchers = new HashMap<String, Dispatcher>(dispatcher.getDispatchers()); + dispatchers = new HashMap<String, Dispatcher>(dispatcherModule.getDispatchers()); dispatchers.put(DispatcherModule.PATH_MAPPED, new MapperDispatcher()); dispatchers.put(DispatcherModule.PATH_GLOBAL_MAPPED, GlobalMapperRegistry.getInstance()); diff --git a/src/main/java/org/olat/group/manager/ContactDAO.java b/src/main/java/org/olat/group/manager/ContactDAO.java index 4373bc65dce..16c8d15e836 100644 --- a/src/main/java/org/olat/group/manager/ContactDAO.java +++ b/src/main/java/org/olat/group/manager/ContactDAO.java @@ -65,9 +65,8 @@ public class ContactDAO { sb.append("select contact.identity.key from ").append(BusinessGroupImpl.class.getName()).append(" bgroup ") .append(" inner join bgroup.baseGroup baseGroup") .append(" inner join baseGroup.members contact") - .append(" inner join baseGroup.members me") - .append(" where me.identity.key=:identKey and ") - .append(" ((bgroup.ownersVisibleIntern=true and contact.role='coach')") + .append(" where exists (select me.key from bgroupmember as me where me.group=baseGroup and me.identity.key=:identKey)") + .append(" and ((bgroup.ownersVisibleIntern=true and contact.role='coach')") .append(" or") .append(" (bgroup.participantsVisibleIntern=true and contact.role='participant'))"); diff --git a/src/main/java/org/olat/repository/RepositoryService.java b/src/main/java/org/olat/repository/RepositoryService.java index eb9ed8a3105..0bf4594b328 100644 --- a/src/main/java/org/olat/repository/RepositoryService.java +++ b/src/main/java/org/olat/repository/RepositoryService.java @@ -84,6 +84,12 @@ public interface RepositoryService { public Group getDefaultGroup(RepositoryEntryRef ref); + /** + * + * @param identity + * @param entry + * @return True if the identity is member of the repository entry and its attached business groups + */ public boolean isMember(IdentityRef identity, RepositoryEntryRef entry); public void filterMembership(IdentityRef identity, List<Long> entries); diff --git a/src/main/java/org/olat/repository/manager/RepositoryEntryMyCourseQueries.java b/src/main/java/org/olat/repository/manager/RepositoryEntryMyCourseQueries.java index 0ff14945f63..fd12ee93936 100644 --- a/src/main/java/org/olat/repository/manager/RepositoryEntryMyCourseQueries.java +++ b/src/main/java/org/olat/repository/manager/RepositoryEntryMyCourseQueries.java @@ -168,11 +168,15 @@ public class RepositoryEntryMyCourseQueries { .append(" inner join v.olatResource as res") .append(" left join v.lifecycle as lifecycle "); } else { - sb.append("select v, ") - .append(" (select count(mark.key) from ").append(MarkImpl.class.getName()).append(" as mark ") - .append(" where mark.creator=ident and mark.resId=v.key and mark.resName='RepositoryEntry'") - .append(" ) as marks,") - .append(" (select count(offer.key) from ").append(OfferImpl.class.getName()).append(" as offer ") + sb.append("select v, "); + if(params.getMarked() != null && params.getMarked().booleanValue()) { + sb.append(" (select count(mark.key) from ").append(MarkImpl.class.getName()).append(" as mark ") + .append(" where mark.creator=ident and mark.resId=v.key and mark.resName='RepositoryEntry'") + .append(" ) as marks,"); + } else { + sb.append(" 1 as marks,"); + } + sb.append(" (select count(offer.key) from ").append(OfferImpl.class.getName()).append(" as offer ") .append(" where offer.resource=res and offer.valid=true") //TODO validity .append(" ) as offers, "); diff --git a/src/main/java/org/olat/repository/model/RepositoryEntrySecurity.java b/src/main/java/org/olat/repository/model/RepositoryEntrySecurity.java index a816d025a6f..8f7420ee049 100644 --- a/src/main/java/org/olat/repository/model/RepositoryEntrySecurity.java +++ b/src/main/java/org/olat/repository/model/RepositoryEntrySecurity.java @@ -83,4 +83,8 @@ public class RepositoryEntrySecurity { public boolean isGroupWaiting() { return groupWaiting; } + + public boolean isMember() { + return owner || courseParticipant || courseCoach || groupParticipant || groupCoach; + } } diff --git a/src/main/java/org/olat/repository/ui/RepositoryEntryRuntimeController.java b/src/main/java/org/olat/repository/ui/RepositoryEntryRuntimeController.java index f46d4e4d18a..963721980d8 100644 --- a/src/main/java/org/olat/repository/ui/RepositoryEntryRuntimeController.java +++ b/src/main/java/org/olat/repository/ui/RepositoryEntryRuntimeController.java @@ -533,7 +533,7 @@ public class RepositoryEntryRuntimeController extends MainLayoutBasicController if(re.getAccess() == RepositoryEntry.ACC_USERS_GUESTS && ureq.getUserSession().getRoles().isGuestOnly()) { launchContent(ureq, security); } else { - AccessResult acResult = acService.isAccessible(re, getIdentity(), false); + AccessResult acResult = acService.isAccessible(re, getIdentity(), security.isMember(), false); if(acResult.isAccessible()) { launchContent(ureq, security); } else if (re != null && acResult.getAvailableMethods().size() > 0) { diff --git a/src/main/java/org/olat/repository/ui/list/RepositoryEntryDetailsController.java b/src/main/java/org/olat/repository/ui/list/RepositoryEntryDetailsController.java index 29c46614a0a..358cbbdfbd3 100644 --- a/src/main/java/org/olat/repository/ui/list/RepositoryEntryDetailsController.java +++ b/src/main/java/org/olat/repository/ui/list/RepositoryEntryDetailsController.java @@ -50,6 +50,7 @@ import org.olat.core.gui.control.WindowControl; import org.olat.core.gui.control.generic.closablewrapper.CloseableModalController; import org.olat.core.helpers.Settings; import org.olat.core.id.OLATResourceable; +import org.olat.core.id.Roles; import org.olat.core.util.Formatter; import org.olat.core.util.StringHelper; import org.olat.core.util.Util; @@ -279,12 +280,14 @@ public class RepositoryEntryDetailsController extends FormBasicController { //load memberships boolean isMember = repositoryService.isMember(getIdentity(), entry); List<Long> authorKeys = repositoryService.getAuthors(entry); + boolean isAuthor = false; if (isMember) { - Boolean isAuthor = Boolean.valueOf(authorKeys.contains(getIdentity().getKey())); - layoutCont.contextPut("isEntryAuthor", isAuthor); + isAuthor = authorKeys.contains(getIdentity().getKey()); + layoutCont.contextPut("isEntryAuthor", new Boolean(isAuthor)); } // push roles to velocity as well - layoutCont.contextPut("roles", ureq.getUserSession().getRoles()); + Roles roles = ureq.getUserSession().getRoles(); + layoutCont.contextPut("roles", roles); //access control String accessI18n = null; @@ -302,7 +305,7 @@ public class RepositoryEntryDetailsController extends FormBasicController { } accessI18n = translate("cif.access.membersonly"); } else { - AccessResult acResult = acService.isAccessible(entry, getIdentity(), false); + AccessResult acResult = acService.isAccessible(entry, getIdentity(), isMember, false); if(acResult.isAccessible()) { String linkText = translate("start.with.type", translate(entry.getOlatResource().getResourceableTypeName())); startLink = uifactory.addFormLink("start", "start", linkText, null, layoutCont, Link.BUTTON + Link.NONTRANSLATED); @@ -405,9 +408,11 @@ public class RepositoryEntryDetailsController extends FormBasicController { layoutCont.contextPut("numUsers", numUsers); // Where is it in use - String referenceDetails = referenceManager.getReferencesToSummary(entry.getOlatResource(), getLocale()); - if (referenceDetails != null) { - layoutCont.contextPut("referenceDetails", referenceDetails); + if(isAuthor || roles.isOLATAdmin() || roles.isInstitutionalResourceManager()) { + String referenceDetails = referenceManager.getReferencesToSummary(entry.getOlatResource(), getLocale()); + if (referenceDetails != null) { + layoutCont.contextPut("referenceDetails", referenceDetails); + } } // Link to bookmark entry diff --git a/src/main/java/org/olat/repository/ui/list/_content/details.html b/src/main/java/org/olat/repository/ui/list/_content/details.html index c7c32dcfc1d..67586fbd1d5 100644 --- a/src/main/java/org/olat/repository/ui/list/_content/details.html +++ b/src/main/java/org/olat/repository/ui/list/_content/details.html @@ -239,7 +239,8 @@ </div> </div> - #if ($referenceDetails && ($isEntryAuthor || $roles.isOLATAdmin() || $roles.isInstitutionalResourceManager())) + #if ($referenceDetails) + <h1>lal</h1> <div class="panel panel-default"> <div class="panel-heading" data-toggle="collapse" data-target="#collapseUsage"> <h3 class="panel-title"> diff --git a/src/main/java/org/olat/resource/accesscontrol/ACService.java b/src/main/java/org/olat/resource/accesscontrol/ACService.java index b844a3553a1..d62aa370ab7 100644 --- a/src/main/java/org/olat/resource/accesscontrol/ACService.java +++ b/src/main/java/org/olat/resource/accesscontrol/ACService.java @@ -68,6 +68,16 @@ public interface ACService { public AccessResult isAccessible(BusinessGroup group, Identity forId, boolean allowNonInteractiveAccess); public AccessResult isAccessible(RepositoryEntry entry, Identity forId, boolean allowNonInteractiveAccess); + + /** + * + * @param entry + * @param forId + * @param knowMember If you know that the forId is a member + * @param allowNonInteractiveAccess + * @return + */ + public AccessResult isAccessible(RepositoryEntry entry, Identity forId, Boolean knowMember, boolean allowNonInteractiveAccess); public Offer createOffer(OLATResource resource, String resourceName); diff --git a/src/main/java/org/olat/resource/accesscontrol/manager/ACFrontendManager.java b/src/main/java/org/olat/resource/accesscontrol/manager/ACFrontendManager.java index d4897a5d873..db02ce5b2d9 100644 --- a/src/main/java/org/olat/resource/accesscontrol/manager/ACFrontendManager.java +++ b/src/main/java/org/olat/resource/accesscontrol/manager/ACFrontendManager.java @@ -121,14 +121,21 @@ public class ACFrontendManager implements ACService { * -Participants have access to the resource<br/> * @param entry * @param forId + * @param knowMember give it if already know as a member * @return */ - public AccessResult isAccessible(RepositoryEntry entry, Identity forId, boolean allowNonInteractiveAccess) { + @Override + public AccessResult isAccessible(RepositoryEntry entry, Identity forId, Boolean knowMember, boolean allowNonInteractiveAccess) { if(!accessModule.isEnabled()) { return new AccessResult(true); } - boolean member = repositoryService.isMember(forId, entry); + boolean member; + if(knowMember == null) { + member = repositoryService.isMember(forId, entry); + } else { + member = knowMember.booleanValue(); + } if(member) { return new AccessResult(true); } @@ -145,6 +152,16 @@ public class ACFrontendManager implements ACService { return isAccessible(forId, offers, allowNonInteractiveAccess); } + @Override + public AccessResult isAccessible(RepositoryEntry entry, Identity forId, boolean allowNonInteractiveAccess) { + if(!accessModule.isEnabled()) { + return new AccessResult(true); + } + + boolean member = repositoryService.isMember(forId, entry); + return isAccessible(entry, forId, new Boolean(member), allowNonInteractiveAccess); + } + /** * * @param resource -- GitLab