FIX: Only use cached topic lists on popState
This commit is contained in:
parent
a96ba8ed78
commit
8b33e659a1
|
@ -24,10 +24,6 @@ export default Ember.Component.extend({
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
// When you click the logo, never use a cached list
|
|
||||||
var session = Discourse.Session.current();
|
|
||||||
session.setProperties({topicList: null, topicListScrollPosition: null});
|
|
||||||
|
|
||||||
Discourse.URL.routeTo('/');
|
Discourse.URL.routeTo('/');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -317,6 +317,7 @@ Discourse.URL = Em.Object.createWithMixins({
|
||||||
}
|
}
|
||||||
|
|
||||||
var transition = router.handleURL(path);
|
var transition = router.handleURL(path);
|
||||||
|
transition._discourse_intercepted = true;
|
||||||
transition.promise.then(function() {
|
transition.promise.then(function() {
|
||||||
if (elementId) {
|
if (elementId) {
|
||||||
|
|
||||||
|
|
|
@ -193,34 +193,40 @@ Discourse.TopicList.reopenClass({
|
||||||
@method list
|
@method list
|
||||||
@param {Object} filter The menu item to filter to
|
@param {Object} filter The menu item to filter to
|
||||||
@param {Object} params Any additional params to pass to TopicList.find()
|
@param {Object} params Any additional params to pass to TopicList.find()
|
||||||
|
@param {Object} extras Additional finding options, such as caching
|
||||||
@returns {Promise} a promise that resolves to the list of topics
|
@returns {Promise} a promise that resolves to the list of topics
|
||||||
**/
|
**/
|
||||||
list: function(filter, params) {
|
list: function(filter, filterParams, extras) {
|
||||||
var session = Discourse.Session.current(),
|
var tracking = Discourse.TopicTrackingState.current();
|
||||||
list = session.get('topicList'),
|
|
||||||
tracking = Discourse.TopicTrackingState.current();
|
|
||||||
|
|
||||||
|
extras = extras || {};
|
||||||
return new Ember.RSVP.Promise(function(resolve) {
|
return new Ember.RSVP.Promise(function(resolve) {
|
||||||
// Try to use the cached version
|
var session = Discourse.Session.current();
|
||||||
if (list && (list.get('filter') === filter) &&
|
|
||||||
_.isEqual(list.get('listParams'), params)) {
|
|
||||||
list.set('loaded', true);
|
|
||||||
|
|
||||||
if (tracking) {
|
if (extras.cached) {
|
||||||
tracking.updateTopics(list.get('topics'));
|
var cachedList = session.get('topicList');
|
||||||
|
|
||||||
|
// Try to use the cached version
|
||||||
|
if (cachedList && (cachedList.get('filter') === filter) &&
|
||||||
|
_.isEqual(cachedList.get('listParams'), filterParams)) {
|
||||||
|
cachedList.set('loaded', true);
|
||||||
|
|
||||||
|
if (tracking) {
|
||||||
|
tracking.updateTopics(cachedList.get('topics'));
|
||||||
|
}
|
||||||
|
return resolve(cachedList);
|
||||||
}
|
}
|
||||||
return resolve(list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform the search
|
// Clear the cache
|
||||||
session.setProperties({topicList: null, topicListScrollPosition: null});
|
session.setProperties({topicList: null, topicListScrollPosition: null});
|
||||||
|
|
||||||
// Clean up any string parameters that might slip through
|
// Clean up any string parameters that might slip through
|
||||||
params = params || {};
|
filterParams = filterParams || {};
|
||||||
Ember.keys(params).forEach(function(k) {
|
Ember.keys(filterParams).forEach(function(k) {
|
||||||
var val = params[k];
|
var val = filterParams[k];
|
||||||
if (val === "undefined" || val === "null" || val === 'false') {
|
if (val === "undefined" || val === "null" || val === 'false') {
|
||||||
params[k] = undefined;
|
filterParams[k] = undefined;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -233,10 +239,10 @@ Discourse.TopicList.reopenClass({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return resolve(Discourse.TopicList.find(filter, _.extend(findParams, params || {})));
|
return resolve(Discourse.TopicList.find(filter, _.extend(findParams, filterParams || {})));
|
||||||
|
|
||||||
}).then(function(list) {
|
}).then(function(list) {
|
||||||
list.set('listParams', params);
|
list.set('listParams', filterParams);
|
||||||
if (tracking) {
|
if (tracking) {
|
||||||
tracking.sync(list, list.filter);
|
tracking.sync(list, list.filter);
|
||||||
tracking.trackIncoming(list.filter);
|
tracking.trackIncoming(list.filter);
|
||||||
|
|
|
@ -21,13 +21,15 @@ export default function(filter, extras) {
|
||||||
this.controllerFor('navigation/default').set('filterMode', filter);
|
this.controllerFor('navigation/default').set('filterMode', filter);
|
||||||
},
|
},
|
||||||
|
|
||||||
model: function(data, transaction) {
|
model: function(data, transition) {
|
||||||
|
|
||||||
// attempt to stop early cause we need this to be called before .sync
|
// attempt to stop early cause we need this to be called before .sync
|
||||||
Discourse.ScreenTrack.current().stop();
|
Discourse.ScreenTrack.current().stop();
|
||||||
|
|
||||||
var findOpts = filterQueryParams(transaction.queryParams);
|
var findOpts = filterQueryParams(transition.queryParams),
|
||||||
return Discourse.TopicList.list(filter, findOpts);
|
extras = { cached: this.isPoppedState(transition) };
|
||||||
|
|
||||||
|
return Discourse.TopicList.list(filter, findOpts, extras);
|
||||||
},
|
},
|
||||||
|
|
||||||
setupController: function(controller, model, trans) {
|
setupController: function(controller, model, trans) {
|
||||||
|
|
|
@ -41,6 +41,10 @@ Discourse.Route = Em.Route.extend({
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
isPoppedState: function(transition) {
|
||||||
|
return (!transition._discourse_intercepted) && (!!transition.intent.url);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue