Skip to content
Permalink
Browse files

GET queries for flat listing

- too much api calls coming through. too much dynamodb costs
- easier to use cloudfront to cache api instead of setting up redis + vpc...
  • Loading branch information
nexus-uw
nexus-uw committed Jan 16, 2020
1 parent 83c2a35 commit 70779298dfd430476b2a26960f116375ea3ac388
Showing with 49 additions and 63 deletions.
  1. +10 −2 middleware/pageview-tracker.ts
  2. +3 −3 nuxt.config.ts
  3. +36 −58 pages/_LANG/_itemType/_subType.vue
@@ -2,14 +2,22 @@ import axios from 'axios'
declare const BASE_API_URL: string

// track page changes
export default function ({ route, }) {
export default function ({ route }) {

// dont track server side page changes...
if (process.server) {
return
}

try {
const pageView = JSON.stringify({
route: route.path,
})
const endpoint = 'track-pageview'
if (typeof navigator === 'undefined' || !navigator.sendBeacon) {
setImmediate(() => axios.post(BASE_API_URL + endpoint, pageView).catch(e => console.error('axios track page view failed', e)))
setImmediate(() =>
axios.post(BASE_API_URL + endpoint, pageView).catch(e => console.error('axios track page view failed', e))
)
} else {
navigator.sendBeacon(BASE_API_URL + endpoint, pageView)
}
@@ -104,9 +104,9 @@ export default <Configuration>{
},
workbox: prod
? {
importScripts: ['custom-service-worker.js'],
globIgnores: ['sw.js', '**/workbox*.js'],
}
importScripts: ['custom-service-worker.js'],
globIgnores: ['sw.js', '**/workbox*.js'],
}
: false,
generate: {
interval: 500,
@@ -48,70 +48,46 @@ async function getShit(
province = null,
vendor = null,
query = null,
sortField = null,
sortOrder = null,
sortField = 'unitCost',
sortOrder = 'ASC',
}
) {
const f = await axios.post(BASE_API_URL + 'graphql', [
{
function format(s) {
return s ? '"' + s + '"' : 'null'
}
const f = await axios.get(BASE_API_URL + 'graphql', {
params: {
query: `{
itemsFlatListings(
page: ${page}
itemType: ${itemType}
subType: "${subType}"
brand:${format(brand)}
province:${province}
vendor:${format(vendor)}
query:${format(query)}
sortField:${sortField}
sortOrder:${sortOrder}
) {
pages
items {
name
brand
img
price
link
unitCost
vendor
}
}
}`,
opName: 'getItemsFlatListings',
query: `
query getItemsFlatListings(
$page: Int
$pageSize: Int
$itemType: ItemType
$subType: String
$province: Province
$vendor: String
$query: String
$sortField: FlatSortField
$sortOrder: SortOrder,
$brand: String
) {
itemsFlatListings(
page: $page
pageSize: $pageSize
itemType: $itemType
subType: $subType
province: $province
vendor: $vendor
sortField: $sortField
query: $query
sortOrder: $sortOrder
brand: $brand
) {
pages
items {
name
brand
img
price
link
unitCost
vendor
}
}
}
`,
variables: {
itemType,
subType,
page,
pageSize,
brand,
province,
vendor,
query,
sortField,
sortOrder,
},
},
//{ query: '{vendors{name}}' },
])
})
const {
data: { itemsFlatListings, errors },
} = f.data[0]
} = f.data
return itemsFlatListings
}
@@ -137,7 +113,9 @@ async function getShit(
}),
// lazy, this should be cached...
$axios
.post(BASE_API_URL + 'graphql', [{ query: '{vendors{name}}', opName: 'vendors' }])
.post(BASE_API_URL + 'graphql', [
{ query: '{vendors{name}}', opName: 'vendors' },
])
.then(f => f.data[0].data.vendors),
])

0 comments on commit 7077929

Please sign in to comment.
You can’t perform that action at this time.