Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use offset when caching TOC info #92

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions morituri/common/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,29 +151,39 @@ def function(r, t):
assert toc.hasTOC()
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.

@rtype: L{table.Table}
"""
tcache = cache.TableCache()
ptable = tcache.get(cddbdiscid, mbdiscid)
itable = None
tdict = {}

if not ptable.object:
self.debug('getTable: cddbdiscid %s, mbdiscid %s not in cache, '
# Ingore old cache, since we do not know what offset it used.
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' % (
cddbdiscid, mbdiscid))
cddbdiscid, mbdiscid, offset))
t = cdrdao.ReadTableTask(device=device)
runner.run(t)
ptable.persist(t.table)
self.debug('getTable: read table %r' % t.table)
itable = t.table
tdict[offset] = itable
ptable.persist(tdict)
self.debug('getTable: read table %r' % itable)
else:
self.debug('getTable: cddbdiscid %s, mbdiscid %s in cache' % (
cddbdiscid, mbdiscid))
ptable.object.unpickled()
self.debug('getTable: loaded table %r' % ptable.object)
itable = ptable.object
self.debug('getTable: cddbdiscid %s, mbdiscid %s in cache for offset %s' % (
cddbdiscid, mbdiscid, offset))
self.debug('getTable: loaded table %r' % itable)

assert itable.hasTOC()

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

# FIXME: the cache should be model/offset specific

def getRipResult(self, cddbdiscid):
"""
Retrieve the persistable RipResult either from our cache (from a
Expand Down
2 changes: 1 addition & 1 deletion morituri/rip/cd.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def do(self, args):

self.itable = self.program.getTable(self.runner,
self.ittoc.getCDDBDiscId(),
self.ittoc.getMusicBrainzDiscId(), self.device)
self.ittoc.getMusicBrainzDiscId(), self.device, self.options.offset)

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