mirror of
https://github.com/flarum/framework.git
synced 2025-06-03 14:33:07 +08:00
Load discussion and posts with one request
Speeds things up a heap. Also fix a whole bunch of bugs with the post stream.
This commit is contained in:
25
ember/app/initializers/find-query-one.js
Normal file
25
ember/app/initializers/find-query-one.js
Normal file
@ -0,0 +1,25 @@
|
||||
import DS from 'ember-data';
|
||||
|
||||
// This can be removed when
|
||||
// https://github.com/emberjs/data/pull/2584 is implemented.
|
||||
|
||||
export default {
|
||||
name: 'find-query-one',
|
||||
initialize: function(container) {
|
||||
DS.Store.reopen({
|
||||
findQueryOne: function(type, id, query) {
|
||||
var store = this;
|
||||
var typeClass = store.modelFor(type);
|
||||
var adapter = store.adapterFor(typeClass);
|
||||
var serializer = store.serializerFor(typeClass);
|
||||
var url = adapter.buildURL(type, id);
|
||||
var ajaxPromise = adapter.ajax(url, 'GET', { data: query });
|
||||
|
||||
return ajaxPromise.then(function(rawPayload) {
|
||||
var extractedPayload = serializer.extract(store, typeClass, rawPayload, id, 'find');
|
||||
return store.push(typeClass, extractedPayload);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user