Skip to content

Commit

Permalink
Added popular tags window option to .ini and improved sql for pop. tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
Neville Newey authored and Neville Newey committed May 28, 2010
1 parent fccf771 commit 02b79e2
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 4 deletions.
4 changes: 2 additions & 2 deletions abraxas/lib/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))')

Expand Down
6 changes: 4 additions & 2 deletions abraxas/model/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

27 changes: 27 additions & 0 deletions db_repository/versions/010_add_created_index_on_tag.py
Original file line number Diff line number Diff line change
@@ -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);
27 changes: 27 additions & 0 deletions db_repository/versions/011_add_lower_index_on_tag.py
Original file line number Diff line number Diff line change
@@ -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);
3 changes: 3 additions & 0 deletions development.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions prod.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 02b79e2

Please sign in to comment.