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) {
|
AbstractClass.prototype.toObject = function (onlySchema) {
|
||||||
// blind faith: we only enumerate properties
|
|
||||||
var data = {};
|
var data = {};
|
||||||
var ds = this.constructor.schema.definitions[this.constructor.modelName];
|
var ds = this.constructor.schema.definitions[this.constructor.modelName];
|
||||||
var properties = ds.properties;
|
var properties = ds.properties;
|
||||||
|
// weird
|
||||||
Object.keys(onlySchema ? properties : this).concat(['id']).forEach(function (property) {
|
Object.keys(onlySchema ? properties : this).concat(['id']).forEach(function (property) {
|
||||||
data[property] = this[property];
|
data[property] = this[property];
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
|
@ -40,11 +40,11 @@ BridgeToRedis.prototype.defineForeignKey = function (model, key, cb) {
|
||||||
BridgeToRedis.prototype.save = function (model, data, callback) {
|
BridgeToRedis.prototype.save = function (model, data, callback) {
|
||||||
this.client.hmset(model + ':' + data.id, data, function (err) {
|
this.client.hmset(model + ':' + data.id, data, function (err) {
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
this.updateIndexes(model, data, callback);
|
this.updateIndexes(model, data.id, data, callback);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
};
|
};
|
||||||
|
|
||||||
BridgeToRedis.prototype.updateIndexes = function (model, data, callback) {
|
BridgeToRedis.prototype.updateIndexes = function (model, id, data, callback) {
|
||||||
var i = this.indexes[model];
|
var i = this.indexes[model];
|
||||||
var schedule = [];
|
var schedule = [];
|
||||||
Object.keys(data).forEach(function (key) {
|
Object.keys(data).forEach(function (key) {
|
||||||
|
@ -52,7 +52,7 @@ BridgeToRedis.prototype.updateIndexes = function (model, data, callback) {
|
||||||
schedule.push([
|
schedule.push([
|
||||||
'sadd',
|
'sadd',
|
||||||
'i:' + model + ':' + key + ':' + data[key],
|
'i:' + model + ':' + key + ':' + data[key],
|
||||||
model + ':' + data.id
|
model + ':' + id
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
@ -107,7 +107,7 @@ BridgeToRedis.prototype.possibleIndexes = function (model, filter) {
|
||||||
|
|
||||||
var foundIndex = [];
|
var foundIndex = [];
|
||||||
Object.keys(filter).forEach(function (key) {
|
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]);
|
foundIndex.push('i:' + model + ':' + key + ':' + filter[key]);
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
@ -186,6 +186,8 @@ BridgeToRedis.prototype.count = function count(model, callback) {
|
||||||
};
|
};
|
||||||
|
|
||||||
BridgeToRedis.prototype.updateAttributes = function updateAttrs(model, id, data, cb) {
|
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