From 52ad8e863986008ac45cf901d9ebefc5e610e92d Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Wed, 18 Jun 2014 05:09:28 +0700 Subject: * top tags cloud --- src/java/com/juick/http/www/PageTemplates.java | 37 ++++++-------------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/src/java/com/juick/http/www/PageTemplates.java b/src/java/com/juick/http/www/PageTemplates.java index e9de8edb..169cec8d 100644 --- a/src/java/com/juick/http/www/PageTemplates.java +++ b/src/java/com/juick/http/www/PageTemplates.java @@ -146,25 +146,22 @@ public class PageTemplates { public static String getPopularTags(Connection sql, int cnt) { String ret = ""; - com.juick.Tag tags[] = new com.juick.Tag[cnt]; - int maxUsageCnt = 0; PreparedStatement stmt = null; ResultSet rs = null; try { - stmt = sql.prepareStatement("SELECT tags.name AS name,COUNT(DISTINCT messages.user_id) AS cnt FROM (messages INNER JOIN messages_tags ON (messages.ts>TIMESTAMPADD(MONTH,-1,NOW()) AND messages.message_id=messages_tags.message_id)) INNER JOIN tags ON messages_tags.tag_id=tags.tag_id WHERE tags.tag_id NOT IN (SELECT tag_id FROM tags_ignore) GROUP BY tags.tag_id ORDER BY cnt DESC LIMIT ?"); - stmt.setInt(1, cnt); + stmt = sql.prepareStatement("SELECT name FROM tags WHERE top=1 ORDER BY name ASC"); rs = stmt.executeQuery(); rs.beforeFirst(); - cnt = 0; while (rs.next()) { - tags[cnt] = new com.juick.Tag(); - tags[cnt].Name = rs.getString(1); - tags[cnt].UsageCnt = rs.getInt(2); - if (tags[cnt].UsageCnt > maxUsageCnt) { - maxUsageCnt = tags[cnt].UsageCnt; + if (!ret.isEmpty()) { + ret += " "; } - cnt++; + try { + ret += "" + Utils.encodeHTML(rs.getString(1)) + ""; + } catch (UnsupportedEncodingException e) { + } + } } catch (SQLException e) { System.err.println(e); @@ -172,24 +169,6 @@ public class PageTemplates { Utils.finishSQL(rs, stmt); } - Arrays.sort(tags, 0, cnt); - - for (int i = 0; i < cnt; i++) { - String tag = Utils.encodeHTML(tags[i].Name); - try { - tag = "" + tag + ""; - } catch (UnsupportedEncodingException e) { - } - - if (tags[i].UsageCnt > maxUsageCnt / 3 * 2) { - ret += "" + tag + " "; - } else if (tags[i].UsageCnt > maxUsageCnt / 3) { - ret += "" + tag + " "; - } else { - ret += tag + " "; - } - } - return ret; } -- cgit v1.2.3