From 1c356f59b25cf92368ff0439c8ed2c0be006dcf7 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Mon, 21 Jul 2014 14:13:52 +0000 Subject: [PATCH] Only load posts once on navigating to content tab No Issue - Loading posts from the API should not be necessary in PostsIndexRoute because its parent resource (PostsRoute) pre-loads the store. Changing the store.find to store.all gets rid of a duplicate network request to load all posts. --- core/client/routes/posts/index.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/core/client/routes/posts/index.js b/core/client/routes/posts/index.js index 52f46cbe60..acd5ec2578 100644 --- a/core/client/routes/posts/index.js +++ b/core/client/routes/posts/index.js @@ -1,20 +1,16 @@ import loadingIndicator from 'ghost/mixins/loading-indicator'; var PostsIndexRoute = Ember.Route.extend(Ember.SimpleAuth.AuthenticatedRouteMixin, loadingIndicator, { - // redirect to first post subroute unless no posts exist + // This route's only function is to determine whether or not a post + // exists to be used for the content preview. It has a parent resource (Posts) + // that is responsible for populating the store. beforeModel: function () { - var self = this; + // the store has been populated so we can work with the local copy + var post = this.store.all('post').get('firstObject'); - return this.store.find('post', { - status: 'all', - staticPages: 'all', - }).then(function (records) { - var post = records.get('firstObject'); - - if (post) { - return self.transitionTo('posts.post', post); - } - }); + if (post) { + return this.transitionTo('posts.post', post); + } } });