Skip to content

Commit d83e2fe

Browse files
committed
use offset when caching TOC info
thomasvs/morituri#92
1 parent 468d6cb commit d83e2fe

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

morituri/common/program.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,29 +151,39 @@ def function(r, t):
151151
assert toc.hasTOC()
152152
return toc
153153

154-
def getTable(self, runner, cddbdiscid, mbdiscid, device):
154+
def getTable(self, runner, cddbdiscid, mbdiscid, device, offset):
155155
"""
156156
Retrieve the Table either from the cache or the drive.
157157
158158
@rtype: L{table.Table}
159159
"""
160160
tcache = cache.TableCache()
161161
ptable = tcache.get(cddbdiscid, mbdiscid)
162+
itable = None
163+
tdict = {}
162164

163-
if not ptable.object:
164-
self.debug('getTable: cddbdiscid %s, mbdiscid %s not in cache, '
165+
# Ingore old cache, since we do not know what offset it used.
166+
if type(ptable.object) is dict:
167+
tdict = ptable.object
168+
169+
if offset in tdict:
170+
itable = tdict[offset]
171+
172+
if not itable:
173+
self.debug('getTable: cddbdiscid %s, mbdiscid %s not in cache for offset %s, '
165174
'reading table' % (
166-
cddbdiscid, mbdiscid))
175+
cddbdiscid, mbdiscid, offset))
167176
t = cdrdao.ReadTableTask(device=device)
168177
runner.run(t)
169-
ptable.persist(t.table)
170-
self.debug('getTable: read table %r' % t.table)
178+
itable = t.table
179+
tdict[offset] = itable
180+
ptable.persist(tdict)
181+
self.debug('getTable: read table %r' % itable)
171182
else:
172-
self.debug('getTable: cddbdiscid %s, mbdiscid %s in cache' % (
173-
cddbdiscid, mbdiscid))
174-
ptable.object.unpickled()
175-
self.debug('getTable: loaded table %r' % ptable.object)
176-
itable = ptable.object
183+
self.debug('getTable: cddbdiscid %s, mbdiscid %s in cache for offset %s' % (
184+
cddbdiscid, mbdiscid, offset))
185+
self.debug('getTable: loaded table %r' % itable)
186+
177187
assert itable.hasTOC()
178188

179189
self.result.table = itable
@@ -182,8 +192,6 @@ def getTable(self, runner, cddbdiscid, mbdiscid, device):
182192
itable.getMusicBrainzDiscId())
183193
return itable
184194

185-
# FIXME: the cache should be model/offset specific
186-
187195
def getRipResult(self, cddbdiscid):
188196
"""
189197
Retrieve the persistable RipResult either from our cache (from a

morituri/rip/cd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def do(self, args):
109109

110110
self.itable = self.program.getTable(self.runner,
111111
self.ittoc.getCDDBDiscId(),
112-
self.ittoc.getMusicBrainzDiscId(), self.device)
112+
self.ittoc.getMusicBrainzDiscId(), self.device, self.options.offset)
113113

114114
assert self.itable.getCDDBDiscId() == self.ittoc.getCDDBDiscId(), \
115115
"full table's id %s differs from toc id %s" % (

0 commit comments

Comments
 (0)