Commit d2573f89 authored by Lukáš Lalinský's avatar Lukáš Lalinský

Always use the oldest track ID as the merge target

parent 7f19fbfd
......@@ -82,8 +82,9 @@ def import_submission(conn, submission):
m['id'], m['track_id'], m['score'] * 100)
all_track_ids.add(m['track_id'])
if len(all_track_ids) > 1:
all_track_ids.remove(match['track_id'])
merge_tracks(conn, match['track_id'], list(all_track_ids))
fingerprint['track_id'] = min(all_track_ids)
all_track_ids.remove(fingerprint['track_id'])
merge_tracks(conn, fingerprint['track_id'], list(all_track_ids))
if not fingerprint['track_id']:
fingerprint['track_id'] = insert_track(conn)
logger.info('Added new track %d', fingerprint['track_id'])
......
......@@ -249,13 +249,16 @@ def test_import_submission_merge_existing_tracks(conn):
assert_false(submission['handled'])
fingerprint = import_submission(conn, submission)
assert_equals(3, fingerprint['id'])
assert_equals(2, fingerprint['track_id'])
assert_equals(1, fingerprint['track_id'])
query = tables.fingerprint.select(tables.fingerprint.c.id == 1)
fingerprint = conn.execute(query).fetchone()
assert_equals(2, fingerprint['track_id'])
assert_equals(1, fingerprint['track_id'])
query = tables.track.select(tables.track.c.id == 1)
track = conn.execute(query).fetchone()
assert_equals(2, track['new_id'])
assert_equals(None, track['new_id'])
query = tables.track.select(tables.track.c.id == 2)
track = conn.execute(query).fetchone()
assert_equals(1, track['new_id'])
@with_database
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment