You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by sn...@apache.org on 2005/10/21 18:41:06 UTC
svn commit: r327220 - in
/incubator/roller/branches/roller_2.0/src/org/roller: business/
business/hibernate/ presentation/ presentation/pagecache/rollercache/
presentation/weblog/actions/ presentation/xmlrpc/
Author: snoopdave
Date: Fri Oct 21 09:40:54 2005
New Revision: 327220
URL: http://svn.apache.org/viewcvs?rev=327220&view=rev
Log:
Fixing ROL-843 by eliminating the redundant and unconfigurable caches in MainPageAction and the PlanetManager impl.
Removed:
incubator/roller/branches/roller_2.0/src/org/roller/presentation/pagecache/rollercache/LRUCacheHandler.java
Modified:
incubator/roller/branches/roller_2.0/src/org/roller/business/PlanetManagerImpl.java
incubator/roller/branches/roller_2.0/src/org/roller/business/hibernate/HibernatePlanetManagerImpl.java
incubator/roller/branches/roller_2.0/src/org/roller/presentation/MainPageAction.java
incubator/roller/branches/roller_2.0/src/org/roller/presentation/weblog/actions/ImportEntriesAction.java
incubator/roller/branches/roller_2.0/src/org/roller/presentation/weblog/actions/WeblogEntryFormAction.java
incubator/roller/branches/roller_2.0/src/org/roller/presentation/xmlrpc/BaseAPIHandler.java
Modified: incubator/roller/branches/roller_2.0/src/org/roller/business/PlanetManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller_2.0/src/org/roller/business/PlanetManagerImpl.java?rev=327220&r1=327219&r2=327220&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.0/src/org/roller/business/PlanetManagerImpl.java (original)
+++ incubator/roller/branches/roller_2.0/src/org/roller/business/PlanetManagerImpl.java Fri Oct 21 09:40:54 2005
@@ -41,13 +41,13 @@
// Cache up to 20 aggregations, each for up to 30 minutes
// TODO: make this aggregation cache configurable
- protected LRUCache2 aggregationsByGroup =
- new LRUCache2(20, 30 * 60 * 1000);
+ //protected LRUCache2 aggregationsByGroup =
+ //new LRUCache2(20, 30 * 60 * 1000);
// Cache up to 20 aggregations, each for up to 30 minutes
// TODO: make this top-subscriptions cache configurable
- protected LRUCache2 topSubscriptionsByGroup =
- new LRUCache2(20, 30 * 60 * 1000);
+ //protected LRUCache2 topSubscriptionsByGroup =
+ //new LRUCache2(20, 30 * 60 * 1000);
private static Log logger =
LogFactory.getFactory().getInstance(PlanetManagerImpl.class);
Modified: incubator/roller/branches/roller_2.0/src/org/roller/business/hibernate/HibernatePlanetManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller_2.0/src/org/roller/business/hibernate/HibernatePlanetManagerImpl.java?rev=327220&r1=327219&r2=327220&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.0/src/org/roller/business/hibernate/HibernatePlanetManagerImpl.java (original)
+++ incubator/roller/branches/roller_2.0/src/org/roller/business/hibernate/HibernatePlanetManagerImpl.java Fri Oct 21 09:40:54 2005
@@ -212,50 +212,45 @@
try
{
String groupHandle = (group == null) ? NO_GROUP : group.getHandle();
- ret = (List)aggregationsByGroup.get(groupHandle);
- if (ret == null)
+ long startTime = System.currentTimeMillis();
+ Session session =
+ ((HibernateStrategy)strategy).getSession();
+ if (group != null)
{
- long startTime = System.currentTimeMillis();
- Session session =
- ((HibernateStrategy)strategy).getSession();
- if (group != null)
- {
- Query query = session.createQuery(
- "select entry from org.roller.pojos.PlanetEntryData entry "
- +"join entry.subscription.groupSubscriptionAssocs assoc "
- +"where assoc.group=:group order by entry.published desc");
- query.setEntity("group", group);
- query.setMaxResults(maxEntries);
- ret = query.list();
- }
- else
- {
- Query query = session.createQuery(
- "select entry from org.roller.pojos.PlanetEntryData entry "
- +"join entry.subscription.groupSubscriptionAssocs assoc "
- +"where "
- +"assoc.group.handle='external' or assoc.group.handle='all'"
- +" order by entry.published desc");
- query.setMaxResults(maxEntries);
- ret = query.list();
- }
- Date retLastUpdated = null;
- if (ret.size() > 0)
- {
- PlanetEntryData entry = (PlanetEntryData)ret.get(0);
- retLastUpdated = entry.getPublished();
- }
- else
- {
- retLastUpdated = new Date();
- }
- aggregationsByGroup.put(groupHandle, ret);
- lastUpdatedByGroup.put(groupHandle, retLastUpdated);
-
- long endTime = System.currentTimeMillis();
- logger.info("Generated aggregation in "
- +((endTime-startTime)/1000.0)+" seconds");
+ Query query = session.createQuery(
+ "select entry from org.roller.pojos.PlanetEntryData entry "
+ +"join entry.subscription.groupSubscriptionAssocs assoc "
+ +"where assoc.group=:group order by entry.published desc");
+ query.setEntity("group", group);
+ query.setMaxResults(maxEntries);
+ ret = query.list();
+ }
+ else
+ {
+ Query query = session.createQuery(
+ "select entry from org.roller.pojos.PlanetEntryData entry "
+ +"join entry.subscription.groupSubscriptionAssocs assoc "
+ +"where "
+ +"assoc.group.handle='external' or assoc.group.handle='all'"
+ +" order by entry.published desc");
+ query.setMaxResults(maxEntries);
+ ret = query.list();
+ }
+ Date retLastUpdated = null;
+ if (ret.size() > 0)
+ {
+ PlanetEntryData entry = (PlanetEntryData)ret.get(0);
+ retLastUpdated = entry.getPublished();
}
+ else
+ {
+ retLastUpdated = new Date();
+ }
+ lastUpdatedByGroup.put(groupHandle, retLastUpdated);
+
+ long endTime = System.currentTimeMillis();
+ logger.info("Generated aggregation in "
+ +((endTime-startTime)/1000.0)+" seconds");
}
catch (Throwable e)
{
@@ -318,23 +313,19 @@
public synchronized List getTopSubscriptions(int max) throws RollerException
{
String groupHandle = NO_GROUP;
- List ret = (List)topSubscriptionsByGroup.get(groupHandle);
- if (ret == null)
+ List ret = null;
+ try
{
- try
- {
- Session session = ((HibernateStrategy)strategy).getSession();
- Criteria criteria =
- session.createCriteria(PlanetSubscriptionData.class);
- criteria.setMaxResults(max);
- criteria.addOrder(Order.desc("inboundblogs"));
- ret = criteria.list();
- }
- catch (HibernateException e)
- {
- throw new RollerException(e);
- }
- topSubscriptionsByGroup.put(groupHandle, ret);
+ Session session = ((HibernateStrategy)strategy).getSession();
+ Criteria criteria =
+ session.createCriteria(PlanetSubscriptionData.class);
+ criteria.setMaxResults(max);
+ criteria.addOrder(Order.desc("inboundblogs"));
+ ret = criteria.list();
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
}
return ret;
}
@@ -343,35 +334,29 @@
PlanetGroupData group, int max) throws RollerException
{
String groupHandle = (group == null) ? NO_GROUP : group.getHandle();
- List ret = (List)topSubscriptionsByGroup.get(groupHandle);
- if (ret == null)
+ List ret = null;
+ try
{
- try
- {
- Session session = ((HibernateStrategy)strategy).getSession();
- Query query = session.createQuery(
- "select sub from org.roller.pojos.PlanetSubscriptionData sub "
- +"join sub.groupSubscriptionAssocs assoc "
- +"where "
- +"assoc.group.handle=:groupHandle "
- +"order by sub.inboundblogs desc");
- query.setString("groupHandle", group.getHandle());
- query.setMaxResults(max);
- ret = query.list();
- }
- catch (HibernateException e)
- {
- throw new RollerException(e);
- }
- topSubscriptionsByGroup.put(groupHandle, ret);
+ Session session = ((HibernateStrategy)strategy).getSession();
+ Query query = session.createQuery(
+ "select sub from org.roller.pojos.PlanetSubscriptionData sub "
+ +"join sub.groupSubscriptionAssocs assoc "
+ +"where "
+ +"assoc.group.handle=:groupHandle "
+ +"order by sub.inboundblogs desc");
+ query.setString("groupHandle", group.getHandle());
+ query.setMaxResults(max);
+ ret = query.list();
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
}
return ret;
}
public synchronized void clearCachedAggregations()
{
- aggregationsByGroup.purge();
- topSubscriptionsByGroup.purge();
lastUpdatedByGroup.clear();
}
Modified: incubator/roller/branches/roller_2.0/src/org/roller/presentation/MainPageAction.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller_2.0/src/org/roller/presentation/MainPageAction.java?rev=327220&r1=327219&r2=327220&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.0/src/org/roller/presentation/MainPageAction.java (original)
+++ incubator/roller/branches/roller_2.0/src/org/roller/presentation/MainPageAction.java Fri Oct 21 09:40:54 2005
@@ -26,10 +26,6 @@
* @struts.action-forward name="main.page" path=".main"
*/
public class MainPageAction extends Action {
- // TODO: make timeouts configurable
- private static TimedHolder mPopularWebsites = new TimedHolder(30 * 60 * 1000);
- private static TimedHolder mRecentEntries = new TimedHolder(120 * 60 * 1000);
- private static TimedHolder mPinnedEntries = new TimedHolder(120 * 60 * 1000);
private static Log mLogger =
LogFactory.getFactory().getInstance(MainPageAction.class);
@@ -66,13 +62,7 @@
return mapping.findForward("main.page");
}
-
- public static void flushMainPageCache() {
- mLogger.debug("Flushing recent and pinned entries");
- mRecentEntries.expire();
- mPinnedEntries.expire();
- }
-
+
/**
* Page model.
*/
@@ -92,13 +82,10 @@
* @param num Number of entries to return (takes effect on next cache refresh)
*/
public List getPopularWebsites(int num) throws RollerException {
- List list = (List)mPopularWebsites.getObject();
- if (list == null) {
- mLogger.debug("Refreshing popular websites list");
- Roller roller = RollerFactory.getRoller();
- list = roller.getRefererManager().getDaysPopularWebsites(num);
- mPopularWebsites.setObject(list);
- }
+ List list = null;
+ mLogger.debug("Refreshing popular websites list");
+ Roller roller = RollerFactory.getRoller();
+ list = roller.getRefererManager().getDaysPopularWebsites(num);
return list;
}
@@ -107,20 +94,17 @@
* @param num Number of entries to return (takes effect on next cache refresh)
*/
public List getRecentWeblogEntries(int num) throws RollerException {
- List list = (List)mRecentEntries.getObject();
+ List list = null;
try {
- if (list == null) {
- mLogger.debug("Refreshing recent entries list");
- Roller roller = RollerFactory.getRoller();
- list = roller.getWeblogManager().getWeblogEntries(
- null, // userName
- null, // startDate
- new Date(), // endDate
- null, // catName
- WeblogEntryData.PUBLISHED, // status
- new Integer(num)); // maxEntries
- mRecentEntries.setObject(list);
- }
+ mLogger.debug("Refreshing recent entries list");
+ Roller roller = RollerFactory.getRoller();
+ list = roller.getWeblogManager().getWeblogEntries(
+ null, // userName
+ null, // startDate
+ new Date(), // endDate
+ null, // catName
+ WeblogEntryData.PUBLISHED, // status
+ new Integer(num)); // maxEntries
} catch (Exception e) {
mLogger.error(e);
}
@@ -132,45 +116,12 @@
* @param num Number of entries to return (takes effect on next cache refresh)
*/
public List getWeblogEntriesPinnedToMain(int num) throws RollerException {
- List list = (List)mPinnedEntries.getObject();
- if (list == null) {
- mLogger.debug("Refreshing pinned entries list");
- Roller roller = RollerFactory.getRoller();
- list = roller.getWeblogManager()
+ List list = null;
+ mLogger.debug("Refreshing pinned entries list");
+ Roller roller = RollerFactory.getRoller();
+ list = roller.getWeblogManager()
.getWeblogEntriesPinnedToMain(new Integer(num));
- mPinnedEntries.setObject(list);
- }
return list;
- }
- }
-
- /** Hold object and expire after timeout passes. */
- public static class TimedHolder {
- private Object obj = null;
- private long updated = 0L;
- private long timeout = 3000L; // 3 seconds ?? -Lance
-
- /** Create holder with timeout */
- public TimedHolder(long timeout) {
- this.timeout = timeout;
- }
- /** Set object and reset the timeout clock */
- public synchronized void setObject(Object obj) {
- this.obj = obj;
- this.updated = new Date().getTime();
- }
- /** Force object to expire */
- public synchronized void expire() {
- this.obj = null;
- }
- /** Get object or null if object has expired */
- public Object getObject() {
- long currentTime = new Date().getTime();
- if ((currentTime - this.updated) > this.timeout) {
- return null;
- } else {
- return this.obj;
- }
}
}
}
Modified: incubator/roller/branches/roller_2.0/src/org/roller/presentation/weblog/actions/ImportEntriesAction.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller_2.0/src/org/roller/presentation/weblog/actions/ImportEntriesAction.java?rev=327220&r1=327219&r2=327220&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.0/src/org/roller/presentation/weblog/actions/ImportEntriesAction.java (original)
+++ incubator/roller/branches/roller_2.0/src/org/roller/presentation/weblog/actions/ImportEntriesAction.java Fri Oct 21 09:40:54 2005
@@ -88,8 +88,6 @@
// Flush the page cache
PageCacheFilter.removeFromCache(request, website);
- // refresh the front page cache
- MainPageAction.flushMainPageCache();
}
else
{
Modified: incubator/roller/branches/roller_2.0/src/org/roller/presentation/weblog/actions/WeblogEntryFormAction.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller_2.0/src/org/roller/presentation/weblog/actions/WeblogEntryFormAction.java?rev=327220&r1=327219&r2=327220&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.0/src/org/roller/presentation/weblog/actions/WeblogEntryFormAction.java (original)
+++ incubator/roller/branches/roller_2.0/src/org/roller/presentation/weblog/actions/WeblogEntryFormAction.java Fri Oct 21 09:40:54 2005
@@ -343,7 +343,6 @@
mLogger.debug("Removing from cache");
RollerRequest rreq = RollerRequest.getRollerRequest(request);
PageCacheFilter.removeFromCache(request, entry.getWebsite());
- MainPageAction.flushMainPageCache();
// Clean up session objects we used
HttpSession session = request.getSession(true);
@@ -635,7 +634,6 @@
// flush caches
PageCacheFilter.removeFromCache(request, wd.getWebsite());
- MainPageAction.flushMainPageCache();
ActionMessages uiMessages = new ActionMessages();
uiMessages.add(null,
Modified: incubator/roller/branches/roller_2.0/src/org/roller/presentation/xmlrpc/BaseAPIHandler.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller_2.0/src/org/roller/presentation/xmlrpc/BaseAPIHandler.java?rev=327220&r1=327219&r2=327220&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.0/src/org/roller/presentation/xmlrpc/BaseAPIHandler.java (original)
+++ incubator/roller/branches/roller_2.0/src/org/roller/presentation/xmlrpc/BaseAPIHandler.java Fri Oct 21 09:40:54 2005
@@ -202,6 +202,5 @@
{
RollerRequest rreq = RollerRequest.getRollerRequest();
PageCacheFilter.removeFromCache( rreq.getRequest(), website);
- MainPageAction.flushMainPageCache();
}
}