Skip to content

Commit

Permalink
GET queries for flat listing
Browse files Browse the repository at this point in the history
- 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 committed Jan 16, 2020
1 parent 83c2a35 commit 7077929
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 63 deletions.
12 changes: 10 additions & 2 deletions middleware/pageview-tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
94 changes: 36 additions & 58 deletions pages/_LANG/_itemType/_subType.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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),
])
Expand Down

0 comments on commit 7077929

Please sign in to comment.