Interface out all action log data model operations
This will allow us to reimplement the logs data model against a non-database system in the near future
This commit is contained in:
parent
a156c91962
commit
b773a18ed8
26 changed files with 714 additions and 902 deletions
|
@ -44,30 +44,34 @@ def find_uncounted_repository():
|
|||
return None
|
||||
|
||||
|
||||
def count_repository_actions(to_count):
|
||||
""" Aggregates repository actions from the LogEntry table for the last day and writes them to
|
||||
the RepositoryActionCount table. Return True if the repository was updated and False
|
||||
otherwise.
|
||||
def count_repository_actions(to_count, day):
|
||||
""" Aggregates repository actions from the LogEntry table for the specified day. Returns the
|
||||
count or None on error.
|
||||
"""
|
||||
today = date.today()
|
||||
yesterday = today - timedelta(days=1)
|
||||
|
||||
# TODO(LogMigrate): Remove the branch once we're back on a single table.
|
||||
def lookup_action_count(model):
|
||||
return (model
|
||||
.select()
|
||||
.where(model.repository == to_count,
|
||||
model.datetime >= yesterday,
|
||||
model.datetime < today)
|
||||
model.datetime >= day,
|
||||
model.datetime < (day + timedelta(days=1)))
|
||||
.count())
|
||||
|
||||
actions = (lookup_action_count(LogEntry3) + lookup_action_count(LogEntry2) +
|
||||
lookup_action_count(LogEntry))
|
||||
|
||||
return actions
|
||||
|
||||
|
||||
def store_repository_action_count(repository, day, action_count):
|
||||
""" Stores the action count for a repository for a specific day. Returns False if the
|
||||
repository already has an entry for the specified day.
|
||||
"""
|
||||
try:
|
||||
RepositoryActionCount.create(repository=to_count, date=yesterday, count=actions)
|
||||
RepositoryActionCount.create(repository=repository, date=day, count=action_count)
|
||||
return True
|
||||
except IntegrityError:
|
||||
logger.debug('Count already written for repository %s', to_count.id)
|
||||
logger.debug('Count already written for repository %s', repository.id)
|
||||
return False
|
||||
|
||||
|
||||
|
|
Reference in a new issue