Skip to content
Snippets Groups Projects
Commit 9c271816 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Add drive to cache | Refactoring | Add refresh command to use in cron

parent 36d5a751
No related branches found
No related tags found
No related merge requests found
from dashboard.caches import DRIVE_CACHE, Cache
from .api import *
def build_drive():
def build_drive(force_update=False):
cached = DRIVE_CACHE.get()
if cached is not False and not force_update:
print("Drive come from cache")
return cached
odrive = {
"teachers": get_all_teachers(),
"rooms": get_all_rooms(),
......@@ -16,7 +22,8 @@ def build_drive():
id = el.id
drive[key][id] = el
DRIVE_CACHE.update(drive)
return drive
drive = build_drive()
\ No newline at end of file
drive = build_drive()
......@@ -118,12 +118,12 @@ class LessonTime(object):
self.rooms = rooms
def parse():
def parse(force_update=False):
global drive
cached = caches.PARSED_LESSONS_CACHE.get()
if cached is not False:
print("Lessons come from cache")
if cached is not False and not force_update:
# print("Lessons come from cache")
return cached
lessons = []
......@@ -139,7 +139,7 @@ def parse():
lessons.append(lesson_obj)
print("Lesson cache was refreshed")
# print("Lesson cache was refreshed")
caches.PARSED_LESSONS_CACHE.update(lessons)
return lessons
......
......@@ -2,7 +2,7 @@ import datetime
from django.utils import timezone
from dashboard import caches
from dashboard import caches, plan_caches
from schoolapps import settings
from schoolapps.settings import LESSONS
from untisconnect.api import format_classes, TYPE_CLASS, TYPE_TEACHER, TYPE_ROOM
......@@ -60,15 +60,15 @@ def parse_lesson_times():
return times
def get_plan(type, id, smart=False, monday_of_week=None):
def get_plan(type, id, smart=False, monday_of_week=None, force_update=False):
""" Generates a plan for type (TYPE_TEACHER, TYPE_CLASS, TYPE_ROOM) and a id of the teacher (class, room)"""
# Check cache
cache = caches.get_cache_for_plan(type, id, smart, monday_of_week)
cache = plan_caches.get_cache_for_plan(type, id, smart, monday_of_week)
cached = cache.get()
print(cached)
if cached is not False:
print("Plan come from cache", cache.id)
# print(cached)
if cached is not False and not force_update:
# print("Plan come from cache", cache.id)
return cached
# Get parsed lessons
......@@ -229,6 +229,6 @@ def get_plan(type, id, smart=False, monday_of_week=None):
for j in range(event.event.from_lesson - 1, event.event.to_lesson):
plan[j][0][i].append(element_container)
print("Refresh plan cache for", cache.id)
# print("Refresh plan cache for", cache.id)
cache.update(plan)
return plan
......@@ -5,7 +5,7 @@ from untisconnect.api import run_default_filter, row_by_row_helper, format_class
TYPE_TEACHER
from untisconnect.api_helper import run_using, untis_split_first, untis_date_to_date, date_to_untis_date
from untisconnect.parse import get_lesson_element_by_id_and_teacher
from untisconnect.drive import build_drive
from untisconnect.drive import drive
TYPE_SUBSTITUTION = 0
TYPE_CANCELLATION = 1
......@@ -28,10 +28,6 @@ def parse_type_of_untis_flags(flags):
return type_
# Build cache
drive = build_drive()
class Substitution(object):
def __init__(self):
self.filled = False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment