From 3eb6e20f1581cf19d922d6bb74063b4a811daa59 Mon Sep 17 00:00:00 2001 From: scottmeng Date: Wed, 23 Apr 2014 18:51:27 +0800 Subject: [PATCH 1/5] quick fix on ranked list insertion --- views/game/featured.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/views/game/featured.js b/views/game/featured.js index f02c881..f76b9ef 100644 --- a/views/game/featured.js +++ b/views/game/featured.js @@ -120,7 +120,12 @@ module.exports = function(server) { var scriptManager = db.scriptManager(); - scriptManager.run('insert_sorted', ['featured-ranked'], [id, rank]); + if (rank) { + scriptManager.run('insert_sorted', ['featured-ranked'], [id, rank]); + } else { + scriptManager.run('insert_sorted', ['featured-ranked'], [id]); + } + genres.forEach(function(genre) { multi.sadd('featured:' + genre, id); From aec3e0416bf0fec0f32e5a3435bab8c3901e53bb Mon Sep 17 00:00:00 2001 From: scottmeng Date: Wed, 23 Apr 2014 19:08:43 +0800 Subject: [PATCH 2/5] simplify script --- lua/insert_sorted.lua | 2 +- views/game/featured.js | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/lua/insert_sorted.lua b/lua/insert_sorted.lua index c39b138..53f6f04 100644 --- a/lua/insert_sorted.lua +++ b/lua/insert_sorted.lua @@ -6,7 +6,7 @@ local count = redis.call("ZCARD", key) local curPosition = redis.call("ZSCORE", key, member) -- if no position is given -if (score == nil) then +if (score == -1) then if (curPosition ~= false) then return 0 else diff --git a/views/game/featured.js b/views/game/featured.js index f76b9ef..3719c41 100644 --- a/views/game/featured.js +++ b/views/game/featured.js @@ -97,7 +97,7 @@ module.exports = function(server) { return done(); } - var rank = DATA.rank || null; + var rank = DATA.rank || -1; var genres = DATA.genres; if (!genres) { @@ -120,12 +120,7 @@ module.exports = function(server) { var scriptManager = db.scriptManager(); - if (rank) { - scriptManager.run('insert_sorted', ['featured-ranked'], [id, rank]); - } else { - scriptManager.run('insert_sorted', ['featured-ranked'], [id]); - } - + scriptManager.run('insert_sorted', ['featured-ranked'], [id, rank]); genres.forEach(function(genre) { multi.sadd('featured:' + genre, id); From 9a523bddac4ff539e1e05ebdec9b41533540b044 Mon Sep 17 00:00:00 2001 From: scottmeng Date: Wed, 23 Apr 2014 19:27:53 +0800 Subject: [PATCH 3/5] remove extra spaces --- views/game/featured.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/game/featured.js b/views/game/featured.js index 3719c41..31ac270 100644 --- a/views/game/featured.js +++ b/views/game/featured.js @@ -120,7 +120,7 @@ module.exports = function(server) { var scriptManager = db.scriptManager(); - scriptManager.run('insert_sorted', ['featured-ranked'], [id, rank]); + scriptManager.run('insert_sorted', ['featured-ranked'], [id, rank]); genres.forEach(function(genre) { multi.sadd('featured:' + genre, id); From 4cecddd5dd81e5d4edd82decc62f482d1cf51459 Mon Sep 17 00:00:00 2001 From: scottmeng Date: Wed, 23 Apr 2014 19:29:24 +0800 Subject: [PATCH 4/5] removing spaces --- views/game/featured.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/game/featured.js b/views/game/featured.js index 31ac270..699fa05 100644 --- a/views/game/featured.js +++ b/views/game/featured.js @@ -120,7 +120,7 @@ module.exports = function(server) { var scriptManager = db.scriptManager(); - scriptManager.run('insert_sorted', ['featured-ranked'], [id, rank]); + scriptManager.run('insert_sorted', ['featured-ranked'], [id, rank]); genres.forEach(function(genre) { multi.sadd('featured:' + genre, id); From 586b4af8c6a088eba7f37a4f32cc301b15e77843 Mon Sep 17 00:00:00 2001 From: scottmeng Date: Wed, 23 Apr 2014 20:23:49 +0800 Subject: [PATCH 5/5] add force casting --- lua/insert_sorted.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/insert_sorted.lua b/lua/insert_sorted.lua index 53f6f04..fa4ed48 100644 --- a/lua/insert_sorted.lua +++ b/lua/insert_sorted.lua @@ -6,7 +6,7 @@ local count = redis.call("ZCARD", key) local curPosition = redis.call("ZSCORE", key, member) -- if no position is given -if (score == -1) then +if ((score + 1) == 0) then if (curPosition ~= false) then return 0 else