use offset when caching TOC info

thomasvs/morituri#92
This commit is contained in:
JoeLametta
2015-11-29 16:19:53 +01:00
parent 468d6cbaf6
commit d83e2fe696
2 changed files with 22 additions and 14 deletions

View File

@@ -151,7 +151,7 @@ class Program(log.Loggable):
assert toc.hasTOC() assert toc.hasTOC()
return toc return toc
def getTable(self, runner, cddbdiscid, mbdiscid, device): def getTable(self, runner, cddbdiscid, mbdiscid, device, offset):
""" """
Retrieve the Table either from the cache or the drive. Retrieve the Table either from the cache or the drive.
@@ -159,21 +159,31 @@ class Program(log.Loggable):
""" """
tcache = cache.TableCache() tcache = cache.TableCache()
ptable = tcache.get(cddbdiscid, mbdiscid) ptable = tcache.get(cddbdiscid, mbdiscid)
itable = None
tdict = {}
if not ptable.object: # Ingore old cache, since we do not know what offset it used.
self.debug('getTable: cddbdiscid %s, mbdiscid %s not in cache, ' if type(ptable.object) is dict:
tdict = ptable.object
if offset in tdict:
itable = tdict[offset]
if not itable:
self.debug('getTable: cddbdiscid %s, mbdiscid %s not in cache for offset %s, '
'reading table' % ( 'reading table' % (
cddbdiscid, mbdiscid)) cddbdiscid, mbdiscid, offset))
t = cdrdao.ReadTableTask(device=device) t = cdrdao.ReadTableTask(device=device)
runner.run(t) runner.run(t)
ptable.persist(t.table) itable = t.table
self.debug('getTable: read table %r' % t.table) tdict[offset] = itable
ptable.persist(tdict)
self.debug('getTable: read table %r' % itable)
else: else:
self.debug('getTable: cddbdiscid %s, mbdiscid %s in cache' % ( self.debug('getTable: cddbdiscid %s, mbdiscid %s in cache for offset %s' % (
cddbdiscid, mbdiscid)) cddbdiscid, mbdiscid, offset))
ptable.object.unpickled() self.debug('getTable: loaded table %r' % itable)
self.debug('getTable: loaded table %r' % ptable.object)
itable = ptable.object
assert itable.hasTOC() assert itable.hasTOC()
self.result.table = itable self.result.table = itable
@@ -182,8 +192,6 @@ class Program(log.Loggable):
itable.getMusicBrainzDiscId()) itable.getMusicBrainzDiscId())
return itable return itable
# FIXME: the cache should be model/offset specific
def getRipResult(self, cddbdiscid): def getRipResult(self, cddbdiscid):
""" """
Retrieve the persistable RipResult either from our cache (from a Retrieve the persistable RipResult either from our cache (from a

View File

@@ -109,7 +109,7 @@ class _CD(logcommand.LogCommand):
self.itable = self.program.getTable(self.runner, self.itable = self.program.getTable(self.runner,
self.ittoc.getCDDBDiscId(), self.ittoc.getCDDBDiscId(),
self.ittoc.getMusicBrainzDiscId(), self.device) self.ittoc.getMusicBrainzDiscId(), self.device, self.options.offset)
assert self.itable.getCDDBDiscId() == self.ittoc.getCDDBDiscId(), \ assert self.itable.getCDDBDiscId() == self.ittoc.getCDDBDiscId(), \
"full table's id %s differs from toc id %s" % ( "full table's id %s differs from toc id %s" % (