Skip to content

Commit

Permalink
More idiomatic syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanoGuerrini committed Feb 16, 2015
1 parent cfda5eb commit 7a82b0a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 24 deletions.
2 changes: 1 addition & 1 deletion djangomaat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Application that optimizes large ordered data set retrieving when using MySql.
"""

VERSION = (1, 4)
VERSION = (1, 4, 1)


def get_version():
Expand Down
26 changes: 11 additions & 15 deletions djangomaat/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
from django.db.transaction import commit_on_success as atomic

from django.contrib.contenttypes.models import ContentType
from django.utils.six import next

from djangomaat.models import MaatRanking
from djangomaat.exceptions import ManagerDoesNotExist, TypologyNotImplemented
from djangomaat.utils import auto_increment
from djangomaat.settings import FLUSH_BATCH_SIZE

GETTER_PREFIX = 'get_pk_list_for_'
Expand Down Expand Up @@ -134,43 +132,41 @@ def flush_ordered_objects(self, logger=None, simulate=False):
attached to.
This method gets called by the management command.
"""
if logger:
if logger is not None:
if simulate:
logger.write('Simulating flushing...\n')
else:
logger.write('Flushing...\n')

for typology, getter in self._typology_getters_iterator():

if logger:
if logger is not None:
logger.write('Handler: {} - Typology: {}\n'.format(self, typology))

if not simulate:
with atomic():
# First, insert the new values, all set as not usable
if logger:
if logger is not None:
logger.write('Insert...')
start = time()

current_position = auto_increment(1)

objects = (MaatRanking(
content_type_id=self._get_content_type().pk,
object_id=object_id,
typology=typology,
usable=False,
position=next(current_position)
) for object_id in getter())
position=index
) for index, object_id in enumerate(getter()))

MaatRanking.objects.bulk_create(objects, FLUSH_BATCH_SIZE)

if logger:
if logger is not None:
end = time()
duration = end - start
logger.write(' done ({:.3f} sec)\n'.format(duration))

# ...then delete the old values...
if logger:
if logger is not None:
logger.write('Delete...')
start = time()

Expand All @@ -179,13 +175,13 @@ def flush_ordered_objects(self, logger=None, simulate=False):
typology=typology,
usable=True).delete()

if logger:
if logger is not None:
end = time()
duration = end - start
logger.write(' done ({:.3f} sec)\n'.format(duration))

# ...and lastly update the inserted values as usable
if logger:
if logger is not None:
logger.write('Update...')
start = time()

Expand All @@ -194,7 +190,7 @@ def flush_ordered_objects(self, logger=None, simulate=False):
typology=typology,
usable=False).update(usable=True)

if logger:
if logger is not None:
end = time()
duration = end - start
logger.write(' done ({:.3f} sec)\n'.format(duration))
Expand Down Expand Up @@ -231,6 +227,6 @@ def __init__(self, handler):
self.handler = handler

def __get__(self, instance, type=None):
if instance != None:
if instance is not None:
raise AttributeError("Handler isn't accessible via {} instances".format(type.__name__))
return self.handler
6 changes: 0 additions & 6 deletions djangomaat/utils.py

This file was deleted.

8 changes: 7 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
Changelog
=========

Version 1.4
Version 1.4.1
=============
* More idiomatic syntax


Version 1.4
===========
* Added migrations files for Django 1.7+


Version 1.3
===========
* Added support for Python >= 3.2
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name=APP_NAME,
version="{0[0]}.{0[1]}".format(__import__(APP_NAME).VERSION[:2]),
version=".".join(map(str, __import__(APP_NAME).VERSION)),
packages=find_packages(),
include_package_data=True,
description = 'Fast MySQL ordering',
Expand Down

0 comments on commit 7a82b0a

Please sign in to comment.