Commit 41b34c74 authored by Lukáš Lalinský's avatar Lukáš Lalinský

Save the fingerprint_id when importing a submission

parent 78f01dc8
......@@ -49,9 +49,6 @@ def import_submission(conn, submission):
mbids.extend(find_puid_mbids(conn, submission['puid'], min_duration, max_duration))
logger.info("Importing submission %d with MBIDs %s",
submission['id'], ', '.join(mbids))
update_stmt = schema.submission.update().where(
schema.submission.c.id == submission['id'])
conn.execute(update_stmt.values(handled=True))
num_unique_items = len(set(submission['fingerprint']))
if num_unique_items < FINGERPRINT_MIN_UNIQUE_ITEMS:
logger.info("Skipping, has only %d unique items", num_unique_items)
......@@ -99,6 +96,9 @@ def import_submission(conn, submission):
for mbid in mbids:
if insert_mbid(conn, fingerprint['track_id'], mbid):
logger.info('Added MBID %s to track %d', mbid, fingerprint['track_id'])
update_stmt = schema.submission.update().where(
schema.submission.c.id == submission['id'])
conn.execute(update_stmt.values(handled=True, fingerprint_id=fingerprint['id']))
return fingerprint
......
......@@ -56,6 +56,7 @@ submission = Table('submission', metadata,
Column('created', DateTime),
Column('handled', Boolean),
Column('meta_id', Integer, ForeignKey('meta.id')),
Column('fingerprint_id', Integer, ForeignKey('fingerprint.id')),
)
stats = Table('stats', metadata,
......
......@@ -42,6 +42,10 @@ ALTER TABLE submission ADD CONSTRAINT submission_fk_format_id
FOREIGN KEY (format_id)
REFERENCES format (id);
ALTER TABLE submission ADD CONSTRAINT submission_fk_fingerprint_id
FOREIGN KEY (fingerprint_id)
REFERENCES fingerprint (id);
ALTER TABLE stats_top_accounts ADD CONSTRAINT stats_top_accounts_fk_account_id
FOREIGN KEY (account_id)
REFERENCES account (id);
......
......@@ -82,9 +82,10 @@ CREATE TABLE submission (
created timestamp with time zone NOT NULL DEFAULT current_timestamp,
source_id int NOT NULL,
mbid uuid,
handled boolean DEFAULT false,
puid uuid,
meta_id int
handled boolean DEFAULT false,
fingerprint_id int
);
CREATE TABLE stats (
......
......@@ -57,6 +57,7 @@ def test_import_submission(conn):
query = tables.submission.select(tables.submission.c.id == id)
submission = conn.execute(query).fetchone()
assert_false(submission['handled'])
assert_equals(None, submission['fingerprint_id'])
fingerprint = import_submission(conn, submission)
assert_equals(1, fingerprint['id'])
assert_equals(5, fingerprint['track_id'])
......@@ -64,6 +65,7 @@ def test_import_submission(conn):
query = tables.submission.select(tables.submission.c.id == id)
submission = conn.execute(query).fetchone()
assert_true(submission['handled'])
assert_equals(1, submission['fingerprint_id'])
# second submission
id = insert_submission(conn, {
'fingerprint': TEST_2_FP_RAW,
......@@ -75,12 +77,14 @@ def test_import_submission(conn):
query = tables.submission.select(tables.submission.c.id == id)
submission = conn.execute(query).fetchone()
assert_false(submission['handled'])
assert_equals(None, submission['fingerprint_id'])
fingerprint = import_submission(conn, submission)
assert_equals(2, fingerprint['id'])
assert_equals(6, fingerprint['track_id'])
query = tables.submission.select(tables.submission.c.id == id)
submission = conn.execute(query).fetchone()
assert_true(submission['handled'])
assert_equals(2, submission['fingerprint_id'])
# third submission (same as the first one)
id = insert_submission(conn, {
'fingerprint': TEST_1_FP_RAW,
......@@ -94,12 +98,14 @@ def test_import_submission(conn):
query = tables.submission.select(tables.submission.c.id == id)
submission = conn.execute(query).fetchone()
assert_false(submission['handled'])
assert_equals(None, submission['fingerprint_id'])
fingerprint = import_submission(conn, submission)
assert_equals(1, fingerprint['id'])
assert_equals(5, fingerprint['track_id'])
query = tables.submission.select(tables.submission.c.id == id)
submission = conn.execute(query).fetchone()
assert_true(submission['handled'])
assert_equals(1, submission['fingerprint_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