Skip to content

Commit

Permalink
Fixed an issue where records could be duplicated if watched history c…
Browse files Browse the repository at this point in the history
…hanges while the scanner is running
  • Loading branch information
fuzeman committed Sep 18, 2016
1 parent 8fe8e36 commit 18a0d71
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
8 changes: 2 additions & 6 deletions tests/tasks/history/duplicates/scan_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ def test_duplicate_single_episode():
]

# Validate records
assert [
r.id for r in episode.records
] == [
assert sorted(episode.records.keys()) == [
1,
2
]
Expand Down Expand Up @@ -185,9 +183,7 @@ def test_duplicate_single_movie():
]

# Validate records
assert [
r.id for r in movie.records
] == [
assert sorted(movie.records.keys()) == [
1,
2
]
Expand Down
4 changes: 4 additions & 0 deletions trakt_tools/tasks/history/duplicates/scan/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ def map_item(self, store, current, create_shows=True):
# Try add record to existing group
record = Record.from_item(current)

if store[key].has_record(record):
log.debug('Ignoring duplicate record: %r', record)
return True

if store[key].add(record, self.delta_max):
return True

Expand Down
9 changes: 6 additions & 3 deletions trakt_tools/tasks/history/duplicates/scan/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, key, title, year, season=None, number=None):
self.children = {}

self.groups = {}
self.records = []
self.records = {}

@property
def duplicated(self):
Expand All @@ -52,7 +52,7 @@ def add(self, current, delta_max):
records.append(current)

# Add record to list
self.records.append(current)
self.records[current.id] = current
return True

return False
Expand All @@ -65,7 +65,10 @@ def create_group(self, record):
self.groups[record.watched_at] = [record]

# Add record to list
self.records.append(record)
self.records[record.id] = record

def has_record(self, record):
return record.id in self.records

def __repr__(self):
fragments = []
Expand Down

0 comments on commit 18a0d71

Please sign in to comment.