Browse files

Added a config option to disable code version checking (currently req…

…uires a MySQL join)
  • Loading branch information...
1 parent 11dabcb commit 8d0ae74842231355799d210907a02bfe9c27431e @jhurliman committed Feb 22, 2012
Showing with 32 additions and 11 deletions.
  1. +5 −1 config.js
  2. +5 −1 config.local.js.orig
  3. +22 −9 models/mysql.js
View
6 config.js
@@ -24,7 +24,11 @@ var settings = {
// Minimum number of codes that must be matched to consider a fingerprint
// match valid
- code_threshold: 10
+ code_threshold: 10,
+
+ // Set this to false to disable code version checking and speed up queries
+ // at the expense of safely supporting multiple codegen versions
+ check_codever: true
};
// Override default settings with any local settings
View
6 config.local.js.orig
@@ -22,5 +22,9 @@ module.exports = {
// Minimum number of codes that must be matched to consider a fingerprint
// match valid
- code_threshold: 10
+ code_threshold: 10,
+
+ // Set this to false to disable code version checking and speed up queries
+ // at the expense of safely supporting multiple codegen versions
+ check_codever: true
};
View
31 models/mysql.js
@@ -32,16 +32,29 @@ var client = mysql.createClient({
function fpQuery(fp, rows, callback) {
var fpCodesStr = fp.codes.join(',');
+ var sql, args;
+ if (config.check_codever) {
+ sql = 'SELECT track_id,COUNT(track_id) AS score ' +
+ 'FROM codes,tracks ' +
+ 'WHERE code IN (' + fpCodesStr + ') ' +
+ 'AND id=track_id ' +
+ 'AND codever=?' +
+ 'GROUP BY track_id ' +
+ 'ORDER BY score DESC ' +
+ 'LIMIT ' + rows;
+ args = [fp.codever];
+ } else {
+ sql = 'SELECT track_id,COUNT(track_id) AS score ' +
+ 'FROM codes ' +
+ 'WHERE code IN (' + fpCodesStr + ') ' +
+ 'GROUP BY track_id ' +
+ 'ORDER BY score DESC ' +
+ 'LIMIT ' + rows;
+ args = [];
+ }
+
// Get the top N matching tracks sorted by score (number of matched codes)
- var sql = 'SELECT track_id,COUNT(track_id) AS score ' +
- 'FROM codes,tracks ' +
- 'WHERE code IN (' + fpCodesStr + ') ' +
- 'AND id=track_id ' +
- 'AND codever=?' +
- 'GROUP BY track_id ' +
- 'ORDER BY score DESC ' +
- 'LIMIT ' + rows;
- client.query(sql, [fp.codever], function(err, matches) {
+ client.query(sql, args, function(err, matches) {
if (err) return callback(err, null);
if (!matches) return callback(null, []);

0 comments on commit 8d0ae74

Please sign in to comment.