/loggerhead/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/loggerhead/trunk

« back to all changes in this revision

Viewing changes to loggerhead/changecache.py

  • Committer: Michael Hudson
  • Date: 2007-08-28 16:11:01 UTC
  • mto: This revision was merged to the branch mainline in revision 138.
  • Revision ID: michael.hudson@canonical.com-20070828161101-zrm230d4v9h3c72k
don't commit so often when building the textindex search

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
        r = dbapi2.Binary(cPickle.dumps(obj, protocol=2))
56
56
        return r
57
57
    def _unserialize(self, data):
58
 
        return cPickle.loads(data)
 
58
        return cPickle.loads(str(data))
59
59
    def get(self, revid):
60
60
        filechange = self.connection.execute(
61
61
            "select data from revisiondata where revid = ?",
64
64
            return None
65
65
        else:
66
66
            return self._unserialize(filechange[0])
67
 
    def add(self, revid_obj_pairs):
 
67
    def add(self, revid_obj_pairs, commit=True):
68
68
        self.connection.executemany(
69
69
            "insert into revisiondata (revid, data) values (?, ?)",
70
70
            [(r, self._serialize(d)) for (r, d) in revid_obj_pairs])
71
 
        self.connection.commit()
72
 
    def update(self, revid_obj_pairs):
 
71
        if commit:
 
72
            self.connection.commit()
 
73
    def update(self, revid_obj_pairs, commit=True):
73
74
        self.connection.executemany(
74
75
            "update revisiondata set data = ? where revid = ?",
75
76
            [(self._serialize(d), r) for (r, d) in revid_obj_pairs])
76
 
        self.connection.commit()
 
77
        if commit:
 
78
            self.connection.commit()
77
79
    def count(self):
78
80
        return self.connection.execute(
79
81
            "select count(*) from revisiondata").fetchone()[0]
80
 
    def close(self):
 
82
    def close(self, commit=False):
 
83
        if commit:
 
84
            self.connection.commit()
81
85
        self.connection.close()
82
86
 
83
87
class ChangeCache (object):
84
 
    
 
88
 
85
89
    def __init__(self, history, cache_path):
86
90
        self.history = history
87
91
        self.log = history.log