Fixed calendar access cache

This commit is contained in:
Adolfo Gómez García 2016-04-26 16:04:29 +02:00
parent 50bc3cd3ef
commit a250cf4aef
2 changed files with 5 additions and 5 deletions

View File

@ -46,7 +46,7 @@ import six
import bitarray import bitarray
import logging import logging
__updated__ = '2016-03-30' __updated__ = '2016-04-26'
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -137,7 +137,7 @@ class CalendarChecker(object):
dtime = getSqlDatetime() dtime = getSqlDatetime()
# First, try to get data from cache if it is valid # First, try to get data from cache if it is valid
cacheKey = six.text_type(self.calendar.modified.toordinal()) + six.text_type(dtime.date().toordinal()) + self.calendar.uuid + 'checker' cacheKey = six.text_type(hash(self.calendar.modified)) + six.text_type(dtime.date().toordinal()) + self.calendar.uuid + 'checker'
cached = CalendarChecker.cache.get(cacheKey, None) cached = CalendarChecker.cache.get(cacheKey, None)
if cached is not None: if cached is not None:
@ -165,7 +165,7 @@ class CalendarChecker(object):
if offset is None: if offset is None:
offset = datetime.timedelta(minutes=0) offset = datetime.timedelta(minutes=0)
cacheKey = six.text_type(self.calendar.modified.toordinal()) + self.calendar.uuid + six.text_type(offset.seconds) + six.text_type(int(time.mktime(checkFrom.timetuple()))) + 'event' + ('x' if startEvent is True else '_') cacheKey = six.text_type(hash(self.calendar.modified)) + self.calendar.uuid + six.text_type(offset.seconds) + six.text_type(int(time.mktime(checkFrom.timetuple()))) + 'event' + ('x' if startEvent is True else '_')
next_event = CalendarChecker.cache.get(cacheKey, None) next_event = CalendarChecker.cache.get(cacheKey, None)
if next_event is None: if next_event is None:
logger.debug('Regenerating cached nextEvent') logger.debug('Regenerating cached nextEvent')

View File

@ -60,7 +60,7 @@ from uds.core.util.calendar import CalendarChecker
from datetime import timedelta from datetime import timedelta
import logging import logging
__updated__ = '2016-04-25' __updated__ = '2016-04-26'
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -200,7 +200,7 @@ class DeployedService(UUIDModel, TaggingMixin):
access = self.fallbackAccess access = self.fallbackAccess
# Let's see if we can access by current datetime # Let's see if we can access by current datetime
for ac in self.calendaraccess_set.all(): for ac in self.calendaraccess_set.order_by('priority'):
if CalendarChecker(ac.calendar).check(chkDateTime) is True: if CalendarChecker(ac.calendar).check(chkDateTime) is True:
access = ac.access access = ac.access
break # Stops on first rule match found break # Stops on first rule match found