Skip to content

Commit

Permalink
merge: v3 to master (#1040)
Browse files Browse the repository at this point in the history
* fix: fixes a bug in refreshMetadata for collection (#1037)

* fix

* fix

* fix: NFTIO-2259 Add category to top collection resolver (#1038)

add categorgy to top collection resolver

* fixes

* fix

* add collection catergory as filter

* allow multiple category as filter
  • Loading branch information
justraman authored May 6, 2024
1 parent f7dd193 commit 98f027e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/job-handlers/compute-traits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default async (job: Queue.Job<JobData>, done: Queue.DoneCallback) => {
if (typeof data === 'object') {
value = data.value
}

if (!value) return

value = value.toString()
Expand Down
5 changes: 2 additions & 3 deletions src/server-extension/resolvers/refresh_metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class RefreshMetadataResponse {
}

const rateLimitMap = new NodeCache({ stdTTL: 60 * 60 * 24, checkperiod: 60 * 60 })
const mins30 = 30 * 1000 * 60 * 10
const mins30 = 30 * 60 * 1000 // 30 minutes in ms

@Resolver()
export class RefreshMetadataResolver {
Expand All @@ -54,11 +54,10 @@ export class RefreshMetadataResolver {
if (timeLeft > 0) {
return {
status: RefreshMetadataResponseStatus.ERROR,
error: `Rate limit exceeded for ${collectionId}, please try again later in ${timeLeft} seconds`,
error: `You exceeded rate limit for ${collectionId}. Please retry after ${timeLeft} seconds.`,
}
}
}

rateLimitMap.set(collectionId, Date.now())
}

Expand Down
11 changes: 11 additions & 0 deletions src/server-extension/resolvers/top_collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ enum TopCollectionOrderBy {
SALES = 'sales',
VOLUME_CHANGE = 'volume_change',
USERS = 'users',
CATEGORY = 'category',
}

enum Order {
Expand Down Expand Up @@ -58,6 +59,9 @@ export class CollectionRow {
@Field(() => Json, { nullable: true })
metadata!: typeof Json

@Field({ nullable: true })
category!: string

@Field(() => Json, { nullable: true })
stats!: typeof JSON

Expand Down Expand Up @@ -86,6 +90,7 @@ export class TopCollectionResolver {
async topCollection(
@Arg('timeFrame', () => Timeframe) timeFrame: Timeframe,
@Arg('orderBy', () => TopCollectionOrderBy) orderBy: TopCollectionOrderBy,
@Arg('category', () => [String], { nullable: true, defaultValue: [] }) category: string[],
@Arg('order', () => Order) order: Order,
@Arg('offset', () => Int) offset: number = 0,
@Arg('limit', () => Int) limit: number = 10
Expand All @@ -100,6 +105,7 @@ export class TopCollectionResolver {
.addSelect('stats AS stats')
.addSelect('volume_last_duration AS volume')
.addSelect('sales_last_duration AS sales')
.addSelect('category AS category')
.addSelect(
'CASE WHEN volume_previous_duration != 0 THEN ROUND((volume_last_duration - volume_previous_duration) * 100 / volume_previous_duration, 2) ELSE null END AS volume_change'
)
Expand All @@ -108,6 +114,7 @@ export class TopCollectionResolver {
.select('collection.id AS collectionId')
.addSelect('collection.metadata AS metadata')
.addSelect('collection.stats AS stats')
.addSelect('collection.category AS category')
if (timeFrame === Timeframe.ALL) {
inBuilder
.addSelect(`SUM(sale.amount * sale.price) AS volume_last_duration`)
Expand All @@ -127,6 +134,10 @@ export class TopCollectionResolver {
.where(`sale.created_at >= NOW() - INTERVAL '${timeFrameMap[timeFrame].p}'`)
}

if (category.length > 0) {
inBuilder.andWhere('collection.category IN (:...category)', { category })
}

inBuilder
.from(ListingSale, 'sale')
.innerJoin(Listing, 'listing', 'listing.id = sale.listing')
Expand Down

0 comments on commit 98f027e

Please sign in to comment.