Tune indexes in redis
This commit is contained in:
parent
35dd198f70
commit
182f3ff12e
|
@ -241,10 +241,10 @@ AbstractClass.prototype.propertyChanged = function (name) {
|
|||
};
|
||||
|
||||
AbstractClass.prototype.toObject = function (onlySchema) {
|
||||
// blind faith: we only enumerate properties
|
||||
var data = {};
|
||||
var ds = this.constructor.schema.definitions[this.constructor.modelName];
|
||||
var properties = ds.properties;
|
||||
// weird
|
||||
Object.keys(onlySchema ? properties : this).concat(['id']).forEach(function (property) {
|
||||
data[property] = this[property];
|
||||
}.bind(this));
|
||||
|
|
|
@ -40,11 +40,11 @@ BridgeToRedis.prototype.defineForeignKey = function (model, key, cb) {
|
|||
BridgeToRedis.prototype.save = function (model, data, callback) {
|
||||
this.client.hmset(model + ':' + data.id, data, function (err) {
|
||||
if (err) return callback(err);
|
||||
this.updateIndexes(model, data, callback);
|
||||
this.updateIndexes(model, data.id, data, callback);
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
BridgeToRedis.prototype.updateIndexes = function (model, data, callback) {
|
||||
BridgeToRedis.prototype.updateIndexes = function (model, id, data, callback) {
|
||||
var i = this.indexes[model];
|
||||
var schedule = [];
|
||||
Object.keys(data).forEach(function (key) {
|
||||
|
@ -52,7 +52,7 @@ BridgeToRedis.prototype.updateIndexes = function (model, data, callback) {
|
|||
schedule.push([
|
||||
'sadd',
|
||||
'i:' + model + ':' + key + ':' + data[key],
|
||||
model + ':' + data.id
|
||||
model + ':' + id
|
||||
]);
|
||||
}
|
||||
}.bind(this));
|
||||
|
@ -107,7 +107,7 @@ BridgeToRedis.prototype.possibleIndexes = function (model, filter) {
|
|||
|
||||
var foundIndex = [];
|
||||
Object.keys(filter).forEach(function (key) {
|
||||
if (this.indexes[model][key]) {
|
||||
if (this.indexes[model][key] && typeof filter[key] === 'string') {
|
||||
foundIndex.push('i:' + model + ':' + key + ':' + filter[key]);
|
||||
}
|
||||
}.bind(this));
|
||||
|
@ -186,6 +186,8 @@ BridgeToRedis.prototype.count = function count(model, callback) {
|
|||
};
|
||||
|
||||
BridgeToRedis.prototype.updateAttributes = function updateAttrs(model, id, data, cb) {
|
||||
this.client.hmset(model + ':' + id, data, cb);
|
||||
this.client.hmset(model + ':' + id, data, function () {
|
||||
this.updateIndexes(model, id, data, cb);
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue