Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
View
76 src/newsrack/database/sql/SQL_DB.java
@@ -2259,15 +2259,77 @@ public boolean newsItemPresentInCategory(Category cat, NewsItem ni)
return getNews(cat, null, null, null, 0, numArts);
}
- public List<NewsItem> getNews(Issue i, Date start, Date end, Source src, int startId, int numArts)
+ public List<NewsItem> getNews(Issue issue, Date start, Date end, Source src, int startId, int numArts)
{
+ Long issueKey = issue.getKey();
+ String cacheKey = (start == null) ? "ISSUE:" + issueKey + (src == null ? "" : ":" + src.getKey()) + ":" + startId + ":" + numArts : null;
+ Object keys = (start == null) ? (List)_cache.get("LIST", cacheKey) : null;
+
+ if (keys == null) {
+ // Initialize ...
+ StringBuffer queryBuf = new StringBuffer();
+ List argList = new ArrayList();
+ List<SQL_ValType> argTypeList = new ArrayList<SQL_ValType>();
+
+ // Init query
+ queryBuf.append("SELECT DISTINCT(c.n_key) FROM cat_news c");
+
+ // Add conditions for feed-specific news
+ if (src != null) {
+ queryBuf.append(" JOIN news_collections nc ON nc.n_key = c.n_key AND nc.feed_key = ?");
+ argList.add(src.getFeed().getKey());
+ argTypeList.add(SQL_ValType.LONG);
+ }
+
+ // Add category-specific conditions
+ queryBuf.append(" WHERE c.c_key IN (");
+ List<Long> allLeafCatKeys = (List<Long>)GET_LEAF_CAT_KEYS_FOR_ISSUE.get(issueKey);
+ Iterator<Long> it = allLeafCatKeys.iterator();
+ while (it.hasNext()) {
+ queryBuf.append(it.next());
+ if (it.hasNext())
+ queryBuf.append(",");
+ }
+ queryBuf.append(")");
+
+ // Add conditions for date-limited news
+ if (start != null) {
+ queryBuf.append(" AND date_stamp >= ? AND date_stamp <= ?");
+ argList.add(new java.sql.Date(start.getTime()));
+ argList.add(new java.sql.Date(end.getTime()));
+ argTypeList.add(SQL_ValType.DATE);
+ argTypeList.add(SQL_ValType.DATE);
+ }
+
+ // Add sorting and limiting constraints
+ queryBuf.append(" ORDER by date_stamp DESC, n_key DESC LIMIT ?, ?");
+ argList.add(startId);
+ argList.add(numArts);
+ argTypeList.add(SQL_ValType.INT);
+ argTypeList.add(SQL_ValType.INT);
+
+ // Have to do this nonsense because generic type info and type parameter info is lost at runtime ...
+ Object[] tmp = argTypeList.toArray();
+ SQL_ValType[] argTypes = new SQL_ValType[tmp.length];
+ int i = 0;
+ for (Object v: tmp) {
+ argTypes[i] = (SQL_ValType)v;
+ i++;
+ }
+
+ if (_log.isDebugEnabled()) _log.debug("Executing: " + queryBuf.toString() + " with start value " + startId);
+
+ // Run the query and fetch news!
+ keys = SQL_StmtExecutor.execute(queryBuf.toString(), SQL_StmtType.QUERY, argList.toArray(), argTypes, null, new GetLongResultProcessor(), false);
+
+ // Caching non-datestamp requests right now
+ if (start == null)
+ _cache.add("LIST", new String[]{issue.getUser().getKey().toString(), "ISSUE:" + issueKey}, cacheKey, keys);
+ }
+
+ // Set up the list of news items
List<NewsItem> news = new ArrayList<NewsItem>();
- List<Long> keys;
- if (start == null)
- keys = (List<Long>)GET_NEWS_KEYS_FROM_ISSUE.execute(new Object[] {i.getKey(), startId, numArts});
- else
- keys = (List<Long>)GET_NEWS_KEYS_FROM_ISSUE_BETWEEN_DATES.execute(new Object[] {i.getKey(), new java.sql.Date(start.getTime()), new java.sql.Date(end.getTime()), startId, numArts});
- for (Long k: keys)
+ for (Long k: (List<Long>)keys)
news.add(getNewsItem(k));
return news;
View
10 src/newsrack/database/sql/SQL_Stmt.java
@@ -562,7 +562,6 @@ public Object processResultSet(ResultSet rs) throws java.sql.SQLException
new GetNewsItemResultProcessor(),
false
),
-**/
GET_NEWS_KEYS_FROM_ISSUE(
"SELECT n_key FROM cat_news cn, categories c WHERE c.t_key = ? AND cn.c_key = c.c_key ORDER by date_stamp DESC, n_key DESC LIMIT ?, ?",
new SQL_ValType[] {LONG, INT, INT},
@@ -579,6 +578,7 @@ public Object processResultSet(ResultSet rs) throws java.sql.SQLException
new GetLongResultProcessor(),
false
),
+**/
GET_LEAF_CAT_KEYS_FOR_NEWSITEM(
"SELECT cn.c_key FROM cat_news cn, categories c WHERE n_key = ? AND cn.c_key = c.c_key AND c.valid = true",
new SQL_ValType[] {LONG},
@@ -805,6 +805,14 @@ public Object processResultSet(ResultSet rs) throws java.sql.SQLException
new GetIssueResultProcessor(),
false
),
+ GET_LEAF_CAT_KEYS_FOR_ISSUE(
+ "SELECT c.c_key FROM categories c WHERE c.t_key = ? AND c.valid = TRUE AND c.rgt = c.lft + 1",
+ new SQL_ValType[] {LONG},
+ SQL_StmtType.QUERY,
+ null,
+ new GetLongResultProcessor(),
+ false
+ ),
GET_CAT_KEYS_FOR_ISSUE(
"SELECT c_key FROM categories WHERE t_key = ? AND valid = true",
new SQL_ValType[] {LONG},
View
5 src/views/ftl/display.newsitem.ftl
@@ -37,10 +37,9 @@ div#newsItemCats {
</div>
<@s.if test="newsItem.leafCategories">
<div id="newsItemCats">
-<#-- This article has been classified in the following NewsRack categories [USER : ISSUE : CATEGORY] <br /> -->
- This article has been classified in the following NewsRack categories [USER :: CATEGORY] <br />
+ This article has been classified in the following NewsRack categories: <br />
<span style="font-weight:bold">
- <@s.iterator value="newsItem.categories">
+ <@s.iterator value="newsItem.leafCategories">
[${user.uid} ::
<a href="<@s.url namespace="/" action="browse" owner="${user.uid}" issue="${issue.name}" catID="${catId}" />">${name}</a>] &nbsp;
</@s.iterator>

No commit comments for this range

Something went wrong with that request. Please try again.