Skip to content

Commit

Permalink
Mark the cache for change, so that we don't change it for no reason
Browse files Browse the repository at this point in the history
  • Loading branch information
dhasegan committed May 7, 2014
1 parent 4c70120 commit cec3ed5
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 7 deletions.
18 changes: 15 additions & 3 deletions app/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,29 @@ def create_timeline_cache():
template = loader.get_template('objects/courses_timeline.html')
timeline_html = template.render(RequestContext(HttpRequest(),context))

cache = HomeCache(cached_html=timeline_html)
cache = TimelineCache(cached_html=timeline_html)
cache.save()

def delete_timeline_cache():
old_cache = HomeCache.objects.earliest('create_time')
old_cache = TimelineCache.objects.earliest('create_time')
old_cache.delete()

def mark_timeline_cache():
cache = TimelineCache.objects.latest('create_time')
cache.should_change_mark = True
cache.save()

def is_marked_timeline_cache():
cache = TimelineCache.objects.latest('create_time')
return cache.should_change_mark

def get_timeline_context():
context = {}

cache = HomeCache.objects.latest('create_time')
if not TimelineCache.objects.all().count():
create_timeline_cache()

cache = TimelineCache.objects.latest('create_time')
timeline_html = cache.cached_html
context["timeline"] = timeline_html

Expand Down
5 changes: 3 additions & 2 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class Comment(models.Model):
def __unicode__(self):
return "Comm" + str(self.id)

class HomeCache(models.Model):
cached_html = models.CharField(max_length=10000)
class TimelineCache(models.Model):
cached_html = models.CharField(max_length=2000000)
should_change_mark = models.NullBooleanField()
create_time = models.DateTimeField(auto_now=True)
4 changes: 4 additions & 0 deletions app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def vote_course(request):
rating.rating = rating_value
rating.save()


if rating_type == OVERALL_R:
mark_timeline_cache()

return redirect(form.cleaned_data['url'])


Expand Down
Binary file modified jCourse/db/database.db
Binary file not shown.
4 changes: 4 additions & 0 deletions scripts/force_remake_cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from app.cache import *

create_timeline_cache()
delete_timeline_cache()
8 changes: 6 additions & 2 deletions scripts/remake_cache.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from app.cache import *

create_timeline_cache()
delete_timeline_cache()
if is_marked_timeline_cache():
create_timeline_cache()
delete_timeline_cache()


# Its important to have two newlines after each script block

0 comments on commit cec3ed5

Please sign in to comment.