Skip to content

Commit

Permalink
Upgraded to latest mysql client version to fix hang, better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jhurliman committed May 27, 2013
1 parent d9edb3a commit b414499
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion controllers/fingerprinter.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ function ingest(fp, callback) {
return callback('Missing or invalid "track" field', null);
if (!fp.artist)
return callback('Missing or invalid "artist" field', null);

fp = cutFPLength(fp, MAX_DURATION);

// Acquire a lock while modifying the database
Expand Down Expand Up @@ -419,6 +419,7 @@ function ingest(fp, callback) {

// Function for creating a new artist and new track
function createArtistAndTrack() {
log.debug('Adding artist "' + fp.artist + '"')
database.addArtist(fp.artist, function(err, artistID) {
if (err) { gMutex.release(); return callback(err, null); }

Expand All @@ -430,6 +431,7 @@ function ingest(fp, callback) {

// Function for creating a new track given an artistID
function createTrack(artistID, artist) {
log.debug('Adding track "' + fp.track + '" for artist "' + artist + '" (' + artistID + ')');
database.addTrack(artistID, fp, function(err, trackID) {
if (err) { gMutex.release(); return callback(err, null); }

Expand Down
7 changes: 6 additions & 1 deletion models/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
var fs = require('fs');
var mysql = require('mysql');
var temp = require('temp');
var log = require('winston');
var config = require('../config');

exports.fpQuery = fpQuery;
Expand All @@ -20,12 +21,13 @@ exports.updateArtist = updateArtist;
exports.disconnect = disconnect;

// Initialize the MySQL connection
var client = mysql.createClient({
var client = mysql.createConnection({
user: config.db_user,
password: config.db_pass,
database: config.db_database,
host: config.db_host
});
client.connect();

/**
*
Expand Down Expand Up @@ -166,13 +168,16 @@ function addTrack(artistID, fp, callback) {
tempName = '/tmp/' + require('path').basename(tempName);

// Write out the codes to a file for bulk insertion into MySQL
log.debug('Writing ' + fp.codes.length + ' codes to temporary file ' + tempName);
writeCodesToFile(tempName, fp, trackID, function(err) {
if (err) return callback(err, null);

// Bulk insert the codes
log.debug('Bulk inserting ' + fp.codes.length + ' codes for track ' + trackID);
sql = 'LOAD DATA LOCAL INFILE ? IGNORE INTO TABLE codes';
client.query(sql, [tempName], function(err, info) {
// Remove the temporary file
log.debug('Removing temporary file ' + tempName);
fs.unlink(tempName, function(err2) {
if (!err) err = err2;
callback(err, trackID);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "echoprint-server",
"version": "0.1.0",
"dependencies": {
"mysql": "0.9.6",
"mysql": "2.0.0-alpha8",
"winston": "0.6.2",
"jade": "0.28.2",
"async": "0.2.6",
Expand Down

0 comments on commit b414499

Please sign in to comment.