Преглед изворни кода

:recycle: imposing limits on homepage requests for posts

tags/0.9.0
J пре 4 година
родитељ
комит
9ae398e838

+ 6
- 2
vue-theme/src/pages/index.vue Прегледај датотеку

@@ -54,10 +54,14 @@ export default {
54 54
         for (let type of postTypes) {
55 55
             const action = `getAll${convertTitleCase(type)}s`
56 56
 
57
+            // Limit the amount of posts because we
58
+            // only need the most recent
59
+            const paramLimit = { limit: 1 }
60
+
57 61
             // We try and fetch EVERYTHING except
58 62
             // for EVENTS and EXHIBITIONS
59 63
             if (!omit.includes(type)) {
60
-                this.$store.dispatch(action)
64
+                this.$store.dispatch(action, null, paramLimit)
61 65
             } else {
62 66
                 // Only grab the current or upcoming on load
63 67
                 const eventsOrExhibitions = await this.$store.dispatch(
@@ -67,7 +71,7 @@ export default {
67 71
                 // If no current or upcoming, get past events
68 72
                 // to fill in the blanks
69 73
                 if (eventsOrExhibitions.length < 1) {
70
-                    this.$store.dispatch(action, sortTypes.past)
74
+                    this.$store.dispatch(action, sortTypes.past, paramLimit)
71 75
                 }
72 76
             }
73 77
         }

+ 2
- 2
vue-theme/src/store/modules/artist.js Прегледај датотеку

@@ -17,13 +17,13 @@ const getters = {
17 17
 }
18 18
 
19 19
 const actions = {
20
-    getAllArtists({ commit }, sortType) {
20
+    getAllArtists({ commit }, sortType, params) {
21 21
         commit('CLEAR_ARTISTS')
22 22
         commit('ARTISTS_LOADED', false)
23 23
         return api.getByType('artist', sortType, artists => {
24 24
             commit('STORE_FETCHED_ARTISTS', { artists })
25 25
             commit('ARTISTS_LOADED', true)
26
-        })
26
+        }, params)
27 27
     },
28 28
     getSingleArtist({ commit }, id) {
29 29
         commit('CLEAR_SINGLE_ARTISTS')

+ 1
- 1
vue-theme/src/store/modules/event.js Прегледај датотеку

@@ -30,7 +30,7 @@ const actions = {
30 30
         return api.getByType('event', sortType, events => {
31 31
             commit('STORE_FETCHED_EVENTS', { events })
32 32
             commit('EVENTS_LOADED', true)
33
-        })
33
+        }, params)
34 34
     },
35 35
     getSingleEvent({ commit }, id) {
36 36
         commit('CLEAR_SINGLE_EVENTS')

+ 1
- 1
vue-theme/src/store/modules/exhibition.js Прегледај датотеку

@@ -32,7 +32,7 @@ const actions = {
32 32
         return api.getByType('exhibition', sortType, exhibitions => {
33 33
             commit('STORE_FETCHED_EXHIBITIONS', { exhibitions })
34 34
             commit('EXHIBITIONS_LOADED', true)
35
-        })
35
+        }, params)
36 36
     },
37 37
     getSingleExhibition({ commit }, id) {
38 38
         commit('CLEAR_SINGLE_EXHIBITIONS')

+ 6
- 2
vue-theme/src/utils/api.js Прегледај датотеку

@@ -8,7 +8,7 @@ const SETTINGS = {
8 8
 }
9 9
 
10 10
 export default {
11
-    getByType(type, sortType, cb) {
11
+    getByType(type, sortType, cb, params) {
12 12
         if (sortType && Object.values(sortTypes).includes(sortType)) {
13 13
             return axios
14 14
                 .get(SETTINGS.API_BASE_PATH + `sort/${type}/${sortType}`)
@@ -20,8 +20,12 @@ export default {
20 20
                     cb(e)
21 21
                 })
22 22
         } else {
23
+            let query = `${type}`
24
+            if(params && params.limit) {
25
+                query = `${type}?limit=${params.limit}`
26
+            }
23 27
             return axios
24
-                .get(SETTINGS.API_BASE_PATH + `${type}`)
28
+                .get(SETTINGS.API_BASE_PATH + query)
25 29
                 .then(response => {
26 30
                     cb(response.data)
27 31
                     return response.data

Loading…
Откажи
Сачувај