Commit 7ef6e7aa authored by Lukáš Lalinský's avatar Lukáš Lalinský

Add submission_count also for fingerprints

parent abdae1a0
......@@ -63,8 +63,16 @@ def insert_fingerprint(conn, data):
'format_id': data.get('format_id'),
'track_id': data['track_id'],
'meta_id': data.get('meta_id'),
'submission_count': 1,
})
id = conn.execute(insert_stmt).inserted_primary_key[0]
logger.debug("Inserted fingerprint %r with data %r", id, data)
return id
def inc_fingerprint_submission_count(conn, id):
update_stmt = schema.fingerprint.update().where(schema.fingerprint.c.id == id)
conn.execute(update_stmt.values(submission_count=sql.text('submission_count+1')))
return True
......@@ -4,10 +4,9 @@
import logging
from sqlalchemy import sql
from acoustid import tables as schema
from acoustid.data.fingerprint import lookup_fingerprint, insert_fingerprint
from acoustid.data.fingerprint import lookup_fingerprint, insert_fingerprint, inc_fingerprint_submission_count
from acoustid.data.musicbrainz import find_puid_mbids, resolve_mbid_redirect
from acoustid.data.track import insert_track, insert_mbid, insert_puid, merge_tracks
logger = logging.getLogger(__name__)
TRACK_MERGE_TRESHOLD = 0.7
......@@ -93,6 +92,8 @@ def import_submission(conn, submission):
if not fingerprint['id']:
fingerprint['id'] = insert_fingerprint(conn, fingerprint)
logger.info('Added new fingerprint %d', fingerprint['id'])
else:
inc_fingerprint_submission_count(conn, fingerprint['id'])
for mbid in mbids:
insert_mbid(conn, fingerprint['track_id'], mbid)
if submission['puid']:
......
......@@ -93,6 +93,7 @@ fingerprint = Table('fingerprint', metadata,
Column('track_id', Integer, ForeignKey('track.id')),
Column('submission_id', Integer, ForeignKey('submission.id')),
Column('meta_id', Integer, ForeignKey('meta.id')),
Column('submission_count', Integer),
)
track_mbid = Table('track_mbid', metadata,
......
......@@ -54,7 +54,8 @@ CREATE TABLE fingerprint (
meta_id int,
submission_id int,
hash_full bytea,
hash_query bytea
hash_query bytea,
submission_count int NOT NULL
);
CREATE TABLE fingerprint_index_queue (
......
......@@ -72,6 +72,9 @@ def test_import_submission(conn):
query = tables.track_puid.select(tables.track_puid.c.track_id == fingerprint['track_id'])
track_puid = conn.execute(query).fetchone()
assert_equals(1, track_puid['submission_count'])
query = tables.fingerprint.select(tables.fingerprint.c.id == fingerprint['id'])
fingerprint = conn.execute(query).fetchone()
assert_equals(1, fingerprint['submission_count'])
# second submission
id = insert_submission(conn, {
'fingerprint': TEST_2_FP_RAW,
......@@ -118,6 +121,9 @@ def test_import_submission(conn):
query = tables.track_puid.select(tables.track_puid.c.track_id == fingerprint['track_id'])
track_puid = conn.execute(query).fetchone()
assert_equals(2, track_puid['submission_count'])
query = tables.fingerprint.select(tables.fingerprint.c.id == fingerprint['id'])
fingerprint = conn.execute(query).fetchone()
assert_equals(2, fingerprint['submission_count'])
@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