Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added popular tags window option to .ini and improved sql for pop. tags.

  • Loading branch information...
commit 02b79e2e6db46afeba3ab470465b8f1a129dc562 1 parent fccf771
Neville Newey authored
View
4 abraxas/lib/base.py
@@ -23,12 +23,12 @@ def __before__(self, **kwds):
mycache = cache.get_cache('hot_tags')
log.debug('before call to mycache.get_value("tags"))')
c.tags = mycache.get_value(key='tags', createfunc=Tag.popular,
- type="memory", expiretime=120)
+ type="memory", expiretime=3600)
log.debug('after call to mycache.get_value("tags"))')
c.sources = mycache.get_value(key='sources', createfunc=Feed.active_feeds,
- type='memory', expiretime=120)
+ type='memory', expiretime=3600)
log.debug('after call to mycache.get_value("feeds"))')
View
6 abraxas/model/tag.py
@@ -17,13 +17,15 @@ class Tag(object):
@staticmethod
def popular():
"""Returns the most popular recent tags"""
+ log.info('*******popular method called in Tag class******')
ntags = int(config.get('ntags', 20))
+ hours = int(config.get('popular_tags_window', 72))
s = text('''
select lower, count(*) tagcount from tag
- where unix_timestamp(now())-unix_timestamp(created)<604800
+ where created > now() - interval :hours hour
group by lower order by tagcount desc, lower
limit :limit
''')
- tags = Session.execute(s, dict(limit=ntags)).fetchall()
+ tags = Session.execute(s, dict(limit=ntags,hours=hours)).fetchall()
return tags
View
27 db_repository/versions/010_add_created_index_on_tag.py
@@ -0,0 +1,27 @@
+import datetime
+
+from sqlalchemy import *
+from migrate import *
+
+from sqlalchemy.databases import mysql
+
+metadata = MetaData(migrate_engine)
+
+# Existing tables
+tag_table = Table('tag', metadata,
+ Column('id', mysql.MSBigInteger(unsigned=True), autoincrement=True, primary_key=True, nullable=False),
+ Column('entry_id', mysql.MSBigInteger(unsigned=True), nullable=False),
+ Column('keyword', VARCHAR(64), server_default="", nullable=False),
+ # The following column is the lowercased version of the tag
+ Column('lower', VARCHAR(64), server_default="", nullable=False),
+ Column('created', TIMESTAMP, default='current_timestamp')
+)
+
+def upgrade():
+ sql = "CREATE INDEX ix_created ON tag (created);"
+ migrate_engine.execute(sql);
+
+
+def downgrade():
+ sql = "DROP INDEX ix_created ON tag;"
+ migrate_engine.execute(sql);
View
27 db_repository/versions/011_add_lower_index_on_tag.py
@@ -0,0 +1,27 @@
+import datetime
+
+from sqlalchemy import *
+from migrate import *
+
+from sqlalchemy.databases import mysql
+
+metadata = MetaData(migrate_engine)
+
+# Existing tables
+tag_table = Table('tag', metadata,
+ Column('id', mysql.MSBigInteger(unsigned=True), autoincrement=True, primary_key=True, nullable=False),
+ Column('entry_id', mysql.MSBigInteger(unsigned=True), nullable=False),
+ Column('keyword', VARCHAR(64), server_default="", nullable=False),
+ # The following column is the lowercased version of the tag
+ Column('lower', VARCHAR(64), server_default="", nullable=False),
+ Column('created', TIMESTAMP, default='current_timestamp')
+)
+
+def upgrade():
+ sql = "CREATE INDEX ix_lower ON tag (lower);"
+ migrate_engine.execute(sql);
+
+
+def downgrade():
+ sql = "DROP INDEX ix_lower ON tag;"
+ migrate_engine.execute(sql);
View
3  development.ini
@@ -47,6 +47,9 @@ logo_file = /static/logo.png
# Number of popular tags to display in the sidebar.
ntags = 10
+# Window for inclusion in popular tags (in hours)
+popular_tags_window = 96
+
# Logging configuration
[loggers]
keys = root, routes, abraxas, sqlalchemy
View
3  prod.ini
@@ -47,6 +47,9 @@ logo_file = /static/logo.png
# Number of popular tags to display in the sidebar.
ntags = 10
+# Window for inclusion in popular tags (in hours)
+popular_tags_window = 72
+
# Logging configuration
[loggers]
keys = root, routes, abraxas, sqlalchemy
Please sign in to comment.
Something went wrong with that request. Please try again.