Optimization: don't SELECT the path twice if it's not there
This commit is contained in:
parent
45ab4501ee
commit
52677d2b5d
@ -221,7 +221,6 @@ class Bitrot(object):
|
|||||||
if self.verbosity:
|
if self.verbosity:
|
||||||
self.report_progress(current_size, total_size)
|
self.report_progress(current_size, total_size)
|
||||||
|
|
||||||
missing_paths.discard(p_uni)
|
|
||||||
try:
|
try:
|
||||||
new_sha1 = sha1(p, self.chunk_size)
|
new_sha1 = sha1(p, self.chunk_size)
|
||||||
except (IOError, OSError) as e:
|
except (IOError, OSError) as e:
|
||||||
@ -231,24 +230,37 @@ class Bitrot(object):
|
|||||||
),
|
),
|
||||||
file=sys.stderr,
|
file=sys.stderr,
|
||||||
)
|
)
|
||||||
|
missing_paths.discard(p_uni)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
cur.execute('SELECT mtime, hash, timestamp FROM bitrot WHERE path=?',
|
if p_uni not in missing_paths:
|
||||||
(p_uni,))
|
# We are not expecting this path, it wasn't in the database yet.
|
||||||
row = cur.fetchone()
|
# It's either new or a rename. Let's handle that.
|
||||||
if not row:
|
|
||||||
stored_path = self.handle_unknown_path(
|
stored_path = self.handle_unknown_path(
|
||||||
cur, p_uni, new_mtime, new_sha1, paths_uni, hashes
|
cur, p_uni, new_mtime, new_sha1, paths_uni, hashes
|
||||||
)
|
)
|
||||||
self.maybe_commit(conn)
|
self.maybe_commit(conn)
|
||||||
|
|
||||||
if p_uni == stored_path:
|
if p_uni == stored_path:
|
||||||
new_paths.append(p_uni)
|
new_paths.append(p_uni)
|
||||||
|
missing_paths.discard(p_uni)
|
||||||
else:
|
else:
|
||||||
renamed_paths.append((stored_path, p_uni))
|
renamed_paths.append((stored_path, p_uni))
|
||||||
missing_paths.discard(stored_path)
|
missing_paths.discard(stored_path)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# At this point we know we're seeing an expected file.
|
||||||
|
missing_paths.discard(p_uni)
|
||||||
|
cur.execute('SELECT mtime, hash, timestamp FROM bitrot WHERE path=?',
|
||||||
|
(p_uni,))
|
||||||
|
row = cur.fetchone()
|
||||||
|
if not row:
|
||||||
|
print(
|
||||||
|
'\rwarning: path disappeared from the database while running:',
|
||||||
|
p_uni,
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
|
||||||
stored_mtime, stored_sha1, stored_ts = row
|
stored_mtime, stored_sha1, stored_ts = row
|
||||||
if int(stored_mtime) != new_mtime:
|
if int(stored_mtime) != new_mtime:
|
||||||
updated_paths.append(p_uni)
|
updated_paths.append(p_uni)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user