Bläddra i källkod

:recycle: imposing limits on homepage requests for posts

tags/0.9.0
J 4 år sedan
förälder
incheckning
9ae398e838

+ 6
- 2
vue-theme/src/pages/index.vue Visa fil

54
         for (let type of postTypes) {
54
         for (let type of postTypes) {
55
             const action = `getAll${convertTitleCase(type)}s`
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
             // We try and fetch EVERYTHING except
61
             // We try and fetch EVERYTHING except
58
             // for EVENTS and EXHIBITIONS
62
             // for EVENTS and EXHIBITIONS
59
             if (!omit.includes(type)) {
63
             if (!omit.includes(type)) {
60
-                this.$store.dispatch(action)
64
+                this.$store.dispatch(action, null, paramLimit)
61
             } else {
65
             } else {
62
                 // Only grab the current or upcoming on load
66
                 // Only grab the current or upcoming on load
63
                 const eventsOrExhibitions = await this.$store.dispatch(
67
                 const eventsOrExhibitions = await this.$store.dispatch(
67
                 // If no current or upcoming, get past events
71
                 // If no current or upcoming, get past events
68
                 // to fill in the blanks
72
                 // to fill in the blanks
69
                 if (eventsOrExhibitions.length < 1) {
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 Visa fil

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

+ 1
- 1
vue-theme/src/store/modules/event.js Visa fil

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

+ 1
- 1
vue-theme/src/store/modules/exhibition.js Visa fil

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

+ 6
- 2
vue-theme/src/utils/api.js Visa fil

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

Laddar…
Avbryt
Spara