[Search] Index directly on mutation
Pass model directly when indexing is triggered via object mutation, to avoid issuing an extra, unnecessary request to the server. Additionally supports indexing of objects which have been created but not yet persisted. Addresses #377.
This commit is contained in:
@@ -121,9 +121,9 @@ define([
|
|||||||
provider = this;
|
provider = this;
|
||||||
|
|
||||||
mutationTopic.listen(function (mutatedObject) {
|
mutationTopic.listen(function (mutatedObject) {
|
||||||
var id = mutatedObject.getId();
|
var id = mutatedObject.getId(),
|
||||||
provider.indexedIds[id] = false;
|
model = mutatedObject.getModel();
|
||||||
provider.scheduleForIndexing(id);
|
provider.index(id, model);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -99,12 +99,15 @@ define([
|
|||||||
.toHaveBeenCalledWith(jasmine.any(Function));
|
.toHaveBeenCalledWith(jasmine.any(Function));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reschedules indexing when mutation occurs', function () {
|
it('re-indexes when mutation occurs', function () {
|
||||||
var mockDomainObject =
|
var mockDomainObject =
|
||||||
jasmine.createSpyObj('domainObj', ['getId']);
|
jasmine.createSpyObj('domainObj', ['getId', 'getModel']),
|
||||||
|
testModel = { some: 'model' };
|
||||||
mockDomainObject.getId.andReturn("some-id");
|
mockDomainObject.getId.andReturn("some-id");
|
||||||
|
mockDomainObject.getModel.andReturn(testModel);
|
||||||
|
spyOn(provider, 'index').andCallThrough();
|
||||||
mutationTopic.listen.mostRecentCall.args[0](mockDomainObject);
|
mutationTopic.listen.mostRecentCall.args[0](mockDomainObject);
|
||||||
expect(provider.scheduleForIndexing).toHaveBeenCalledWith('some-id');
|
expect(provider.index).toHaveBeenCalledWith('some-id', testModel);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('starts indexing roots', function () {
|
it('starts indexing roots', function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user