Skip to content

Commit

Permalink
SAK-24944 Mysql Optimizer bug in forums
Browse files Browse the repository at this point in the history
This is an issue with the MYSQL Optimizer where a bad plan is cached
and performance is greatly affected. It is generally not a good idea
to override a DB's optimzer but this issue has created enough problems
to warrant its addition.
  • Loading branch information
ern committed Jun 1, 2015
1 parent 4b6391a commit 0e9be82
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,9 @@ public int getNumModTopicCurrentUserHasModPermForWithPermissionLevel(final List

LOG.debug("getNumModTopicCurrentUserHasModPermForWithPermissionLevel executing with membershipItems: " + membershipList);

// hibernate will not like an empty list so return 0
if (membershipList.isEmpty()) return 0;

HibernateCallback hcb = new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Query q = session.getNamedQuery(QUERY_GET_NUM_MOD_TOPICS_WITH_MOD_PERM_BY_PERM_LEVEL);
Expand All @@ -1517,9 +1520,29 @@ public int getNumModTopicCurrentUserHasModPermForWithPermissionLevelName(final L

LOG.debug("getNumModTopicCurrentUserHasModPermForWithPermissionLevelName executing with membershipItems: " + membershipList);

// hibernate will not like an empty list so return 0
if (membershipList.isEmpty()) return 0;

HibernateCallback hcb = new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Query q = session.getNamedQuery(QUERY_GET_NUM_MOD_TOPICS_WITH_MOD_PERM_BY_PERM_LEVEL_NAME);
Query q = null;
if ("mysql".equals(serverConfigurationService.getString("[email protected]"))) {
q = session.createSQLQuery("select straight_join count(*) as NBR " +
"from MFR_AREA_T area " +
"inner join MFR_OPEN_FORUM_T openforum on openforum.surrogateKey=area.ID inner " +
"join MFR_TOPIC_T topic on topic.of_surrogateKey=openforum.ID " +
"inner join MFR_MEMBERSHIP_ITEM_T membership on topic.ID=membership.t_surrogateKey, " +
"MFR_PERMISSION_LEVEL_T permission " +
"where area.CONTEXT_ID = :contextId " +
"and topic.MODERATED = true " +
"and (membership.NAME in ( :membershipList ) " +
"and permission.MODERATE_POSTINGS = true " +
"and permission.TYPE_UUID <> :customTypeUuid " +
"and permission.NAME=membership.PERMISSION_LEVEL_NAME)")
.addScalar("NBR", Hibernate.INTEGER);
} else {
q = session.getNamedQuery(QUERY_GET_NUM_MOD_TOPICS_WITH_MOD_PERM_BY_PERM_LEVEL_NAME);
}
q.setParameterList("membershipList", membershipList);
q.setParameter("contextId", getContextId(), Hibernate.STRING);
q.setParameter("customTypeUuid", typeManager.getCustomLevelType(), Hibernate.STRING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,9 @@ public List getCurrentUserMemberships(String siteId)
List userMemberships = new ArrayList();
// first, add the user's role
final String currRole = getCurrentUserRole(siteId);
userMemberships.add(currRole);
if (currRole != null && !currRole.isEmpty()) {
userMemberships.add(currRole);
}
// now, add any groups the user is a member of
try {
Site site = SiteService.getSite(toolManager.getCurrentPlacement().getContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@
</query>

<!-- second check by permissionLevelName if permissionLevel id is null -->
<!-- *** If you update this query you need to update the straight join in MessageForumsForumManagerImpl.java *** -->
<query name="findNumModeratedTopicsForSiteByUserByMembershipWithPermissionLevelName">
<![CDATA[select count(*) from org.sakaiproject.component.app.messageforums.dao.hibernate.TopicImpl as topic,
org.sakaiproject.component.app.messageforums.dao.hibernate.PermissionLevelImpl as pl
Expand Down

0 comments on commit 0e9be82

Please sign in to comment.