mirror of
https://github.com/correl/dejavu.git
synced 2024-11-23 19:19:53 +00:00
Changed default cursor type for mysql from DictCursor to Cursor.
This commit is contained in:
parent
6f4cadafbb
commit
05adf3bc31
2 changed files with 10 additions and 10 deletions
|
@ -26,7 +26,7 @@ class Cursor(object):
|
||||||
"""
|
"""
|
||||||
_cache = Queue.Queue(maxsize=5)
|
_cache = Queue.Queue(maxsize=5)
|
||||||
|
|
||||||
def __init__(self, cursor_type=mysql.cursors.DictCursor, **options):
|
def __init__(self, cursor_type=mysql.cursors.Cursor, **options):
|
||||||
super(Cursor, self).__init__()
|
super(Cursor, self).__init__()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -2,7 +2,7 @@ from __future__ import absolute_import
|
||||||
from itertools import izip_longest
|
from itertools import izip_longest
|
||||||
|
|
||||||
from dejavu.cursor import cursor_factory
|
from dejavu.cursor import cursor_factory
|
||||||
from MySQLdb.cursors import Cursor
|
from MySQLdb.cursors import DictCursor
|
||||||
|
|
||||||
|
|
||||||
class Database(object):
|
class Database(object):
|
||||||
|
@ -175,7 +175,6 @@ class SQLDatabase(Database):
|
||||||
|
|
||||||
self.setup()
|
self.setup()
|
||||||
|
|
||||||
|
|
||||||
def delete_unfingerprinted_songs(self):
|
def delete_unfingerprinted_songs(self):
|
||||||
"""
|
"""
|
||||||
Removes all songs that have no fingerprints associated with them.
|
Removes all songs that have no fingerprints associated with them.
|
||||||
|
@ -201,8 +200,9 @@ class SQLDatabase(Database):
|
||||||
with self.cursor() as cur:
|
with self.cursor() as cur:
|
||||||
cur.execute(self.SELECT_NUM_FINGERPRINTS)
|
cur.execute(self.SELECT_NUM_FINGERPRINTS)
|
||||||
|
|
||||||
for row in cur:
|
for count, in cur:
|
||||||
return row['n']
|
return count
|
||||||
|
return 0
|
||||||
|
|
||||||
def set_song_fingerprinted(self, sid):
|
def set_song_fingerprinted(self, sid):
|
||||||
"""
|
"""
|
||||||
|
@ -216,7 +216,7 @@ class SQLDatabase(Database):
|
||||||
"""
|
"""
|
||||||
Return songs that have the fingerprinted flag set TRUE (1).
|
Return songs that have the fingerprinted flag set TRUE (1).
|
||||||
"""
|
"""
|
||||||
with self.cursor() as cur:
|
with self.cursor(cursor_type=DictCursor) as cur:
|
||||||
cur.execute(self.SELECT_SONGS)
|
cur.execute(self.SELECT_SONGS)
|
||||||
for row in cur:
|
for row in cur:
|
||||||
yield row
|
yield row
|
||||||
|
@ -225,7 +225,7 @@ class SQLDatabase(Database):
|
||||||
"""
|
"""
|
||||||
Returns song by its ID.
|
Returns song by its ID.
|
||||||
"""
|
"""
|
||||||
with self.cursor() as cur:
|
with self.cursor(cursor_type=DictCursor) as cur:
|
||||||
cur.execute(self.SELECT_SONG, (sid,))
|
cur.execute(self.SELECT_SONG, (sid,))
|
||||||
return cur.fetchone()
|
return cur.fetchone()
|
||||||
|
|
||||||
|
@ -256,8 +256,8 @@ class SQLDatabase(Database):
|
||||||
|
|
||||||
with self.cursor() as cur:
|
with self.cursor() as cur:
|
||||||
cur.execute(query)
|
cur.execute(query)
|
||||||
for row in cur:
|
for sid, offset in cur:
|
||||||
yield (row[self.FIELD_SONG_ID], row[self.FIELD_OFFSET])
|
yield (sid, offset)
|
||||||
|
|
||||||
def get_iterable_kv_pairs(self):
|
def get_iterable_kv_pairs(self):
|
||||||
"""
|
"""
|
||||||
|
@ -294,7 +294,7 @@ class SQLDatabase(Database):
|
||||||
# Get an iteratable of all the hashes we need
|
# Get an iteratable of all the hashes we need
|
||||||
values = mapper.keys()
|
values = mapper.keys()
|
||||||
|
|
||||||
with self.cursor(cursor_type=Cursor) as cur:
|
with self.cursor() as cur:
|
||||||
for split_values in grouper(values, 1000):
|
for split_values in grouper(values, 1000):
|
||||||
# Create our IN part of the query
|
# Create our IN part of the query
|
||||||
query = self.SELECT_MULTIPLE
|
query = self.SELECT_MULTIPLE
|
||||||
|
|
Loading…
Reference in a new issue