Skip to content

Commit

Permalink
Merge pull request #218 from poap-xyz/release/v1.12.9
Browse files Browse the repository at this point in the history
Release v1.12.9
  • Loading branch information
jm42 authored May 9, 2024
2 parents 1615bc7 + 32c65f7 commit cb5d885
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 25 deletions.
15 changes: 9 additions & 6 deletions netlify/loaders/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export async function getEventInfo(eventId, env) {
return null
}
const response = await fetch(
`${env.FAMILY_API_URL}/event/${eventId}?description=false&metrics=true&fresh=false&refresh=true`,
`${env.FAMILY_API_URL}/event/${eventId}?description=false&metrics=true&fresh=true&refresh=false`,
{
headers: {
'x-api-key': env.FAMILY_API_KEY,
Expand Down Expand Up @@ -142,11 +142,14 @@ export async function getEventsMetrics(eventIds, env) {
if (!env.FAMILY_API_KEY) {
throw new Error(`Events (${eventIds.length}) metrics could not be fetched, configure Family API key`)
}
const response = await fetch(`${env.FAMILY_API_URL}/events/${eventIds.map((eventId) => encodeURIComponent(eventId)).join(',')}/metrics`, {
headers: {
'x-api-key': env.FAMILY_API_KEY,
},
})
const response = await fetch(
`${env.FAMILY_API_URL}/events/${eventIds.map((eventId) => encodeURIComponent(eventId)).join(',')}/metrics?fresh=true`,
{
headers: {
'x-api-key': env.FAMILY_API_KEY,
},
}
)
if (response.status === 404) {
return null
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/poap-family",
"version": "1.12.8",
"version": "1.12.9",
"author": {
"name": "POAP",
"url": "https://poap.xyz"
Expand Down
37 changes: 23 additions & 14 deletions src/loaders/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,16 +296,21 @@ async function getEventsOwners(eventIds, abortSignal, expiryDates, fresh = true)
return body
}

async function getEventMetrics(eventId, abortSignal, refresh = false) {
async function getEventMetrics(eventId, abortSignal, refresh = false, fresh = true) {
if (!FAMILY_API_KEY) {
throw new Error(`Event ${eventId} metrics could not be fetched, configure Family API key`)
}
const response = await fetch(`${FAMILY_API_URL}/event/${eventId}/metrics?refresh=${encodeURIComponent(refresh)}`, {
signal: abortSignal instanceof AbortSignal ? abortSignal : null,
headers: {
'x-api-key': FAMILY_API_KEY,
},
})
const response = await fetch(
`${FAMILY_API_URL}/event/${eventId}/metrics?` +
`refresh=${encodeURIComponent(refresh)}&` +
`fresh=${encodeURIComponent(fresh)}`,
{
signal: abortSignal instanceof AbortSignal ? abortSignal : null,
headers: {
'x-api-key': FAMILY_API_KEY,
},
}
)
if (response.status === 404) {
return null
}
Expand Down Expand Up @@ -335,16 +340,20 @@ async function getEventMetrics(eventId, abortSignal, refresh = false) {
}
}

async function getEventsMetrics(eventIds, abortSignal) {
async function getEventsMetrics(eventIds, abortSignal, fresh = true) {
if (!FAMILY_API_KEY) {
throw new Error(`Events (${eventIds.length}) metrics could not be fetched, configure Family API key`)
}
const response = await fetch(`${FAMILY_API_URL}/events/${eventIds.map((eventId) => encodeURIComponent(eventId)).join(',')}/metrics`, {
signal: abortSignal instanceof AbortSignal ? abortSignal : null,
headers: {
'x-api-key': FAMILY_API_KEY,
},
})
const response = await fetch(
`${FAMILY_API_URL}/events/${eventIds.map((eventId) => encodeURIComponent(eventId)).join(',')}/metrics?` +
`fresh=${encodeURIComponent(fresh)}`,
{
signal: abortSignal instanceof AbortSignal ? abortSignal : null,
headers: {
'x-api-key': FAMILY_API_KEY,
},
}
)
if (response.status === 404) {
return null
}
Expand Down
2 changes: 1 addition & 1 deletion src/loaders/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ async function eventLoader({ params, request }) {
}
const [tokensSettled, metricsSettled] = await Promise.allSettled([
fetchPOAPs(params.eventId),
getEventMetrics(params.eventId, null, /*refresh*/force === 'true'),
getEventMetrics(params.eventId, null, /*refresh*/force === 'true', /*fresh*/true),
])
if (tokensSettled.status === 'rejected') {
throw new Response('', {
Expand Down
9 changes: 6 additions & 3 deletions src/pages/Events.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function Events() {
setLoading((alsoLoading) => ({ ...alsoLoading, [eventId]: LOADING_OWNERS }))
return Promise.allSettled([
fetchPOAPs(eventId, abortSignal),
getEventMetrics(eventId, abortSignal, searchParams.get('force') === 'true'),
getEventMetrics(eventId, abortSignal, searchParams.get('force') === 'true', /*fresh*/true),
]).then(
([eventOwnerTokensResult, eventMetricsResult]) => {
removeLoading(eventId)
Expand Down Expand Up @@ -338,11 +338,14 @@ function Events() {
const expiryDates = parseExpiryDates(events)
Promise.all([
getEventsOwners(eventIds, controller.signal, expiryDates, /*fresh*/false),
getEventsMetrics(eventIds, controller.signal),
getEventsMetrics(eventIds, controller.signal, /*fresh*/true),
]).then(
([newOwners, eventsMetrics]) => {
if (eventsMetrics) {
setMetrics((oldReservations) => ({ ...oldReservations, ...eventsMetrics }))
const foundMetrics = Object.fromEntries(
Object.entries(eventsMetrics).filter(([, metrics]) => metrics != null)
)
setMetrics((oldReservations) => ({ ...oldReservations, ...foundMetrics }))
}
if (newOwners) {
setOwners((oldOwners) => ({ ...oldOwners, ...newOwners }))
Expand Down

0 comments on commit cb5d885

Please sign in to comment.