diff --git a/src/web/dbdjango.py b/src/web/dbdjango.py index 9a9c8c258..48d67ef58 100644 --- a/src/web/dbdjango.py +++ b/src/web/dbdjango.py @@ -27,6 +27,7 @@ # #------------------------------------------------------------------------ import cPickle +import base64 import web import gen from gen.db import DbReadBase, DbWriteBase @@ -187,7 +188,7 @@ class DbDjango(DbWriteBase, DbReadBase): def make_family(self, family): if family.cache: - data = cPickle.loads(str(family.cache)) + data = cPickle.loads(base64.decodestring(family.cache)) obj = gen.lib.Family.create(data) else: data = self.dji.get_family(family) @@ -196,7 +197,7 @@ class DbDjango(DbWriteBase, DbReadBase): def make_person(self, person): if person.cache: - data = cPickle.loads(str(person.cache)) + data = cPickle.loads(base64.decodestring(person.cache)) obj = gen.lib.Person.create(data) else: data = self.dji.get_person(person) diff --git a/src/web/libdjango.py b/src/web/libdjango.py index b5dc21530..d5c3767c0 100644 --- a/src/web/libdjango.py +++ b/src/web/libdjango.py @@ -28,6 +28,8 @@ #------------------------------------------------------------------------ import time import sys +import cPickle +import base64 #------------------------------------------------------------------------ # @@ -1396,3 +1398,78 @@ class DjangoInterface(object): self.add_media_ref_list(event, media_list) self.add_source_ref_list(event, source_list) + def rebuild_caches(self, callback=None): + """ + Call this to rebuild the caches for all primary models. + """ + if not callable(callback): + callback = lambda (percent): None # dummy + + callback(0) + count = 0.0 + total = (self.Note.all().count() + + self.Person.all().count() + + self.Event.all().count() + + self.Family.all().count() + + self.Repository.all().count() + + self.Place.all().count() + + self.Media.all().count() + + self.Source.all().count()) + + for item in self.Person.all(): + raw = self.get_person(item) + item.cache = base64.encodestring(cPickle.dumps(raw)) + item.save() + callback(100 * count/total) + count += 1 + + for item in self.Family.all(): + raw = self.get_family(item) + item.cache = base64.encodestring(cPickle.dumps(raw)) + item.save() + callback(100 * count/total) + count += 1 + + for item in self.Source.all(): + raw = self.get_source(item) + item.cache = base64.encodestring(cPickle.dumps(raw)) + item.save() + callback(100 * count/total) + count += 1 + + for item in self.Event.all(): + raw = self.get_event(item) + item.cache = base64.encodestring(cPickle.dumps(raw)) + item.save() + callback(100 * count/total) + count += 1 + + for item in self.Repository.all(): + raw = self.get_repository(item) + item.cache = base64.encodestring(cPickle.dumps(raw)) + item.save() + callback(100 * count/total) + count += 1 + + for item in self.Place.all(): + raw = self.get_place(item) + item.cache = base64.encodestring(cPickle.dumps(raw)) + item.save() + callback(100 * count/total) + count += 1 + + for item in self.Media.all(): + raw = self.get_media(item) + item.cache = base64.encodestring(cPickle.dumps(raw)) + item.save() + callback(100 * count/total) + count += 1 + + for item in self.Note.all(): + raw = self.get_note(item) + item.cache = base64.encodestring(cPickle.dumps(raw)) + item.save() + callback(100 * count/total) + count += 1 + + callback(100)