Skip to content

Commit 569592c

Browse files
Merge pull request #265 from decentraland/fix/ranking-queries
fix: ranking queries
2 parents b4b21bb + c64c12c commit 569592c

File tree

1 file changed

+48
-16
lines changed

1 file changed

+48
-16
lines changed

src/ports/rankings/queries.ts

+48-16
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,36 @@ export function getCreatorsDayDataQuery(filters: RankingsFilters, page = 0) {
190190

191191
return filters.from === 0
192192
? SQL`
193-
SELECT id, sales, earned, unique_collections_sales, unique_collectors_total
194-
FROM accounts
195-
WHERE `.append(where).append(SQL`
196-
ORDER BY ${orderBy} ${orderDirection}
193+
SELECT id, sales, earned, unique_collections_sales as "uniqueCollectionsSales", unique_collectors_total as "uniqueCollectorsTotal"
194+
FROM `
195+
.append(MARKETPLACE_SQUID_SCHEMA)
196+
.append(
197+
SQL`.accounts
198+
WHERE `
199+
.append(where)
200+
.append(
201+
SQL`
202+
ORDER BY ${orderBy}`.append(orderDirection).append(SQL`
197203
${filters.first ? SQL`LIMIT ${filters.first}` : SQL``}
198204
`)
205+
)
206+
)
199207
: SQL`
200-
SELECT id, sales, earned, unique_collections_sales, unique_collectors_total
201-
FROM accounts_day_data
202-
WHERE `.append(where).append(SQL`
203-
ORDER BY ${orderBy} ${orderDirection}
208+
SELECT id, sales, earned, unique_collections_sales as "uniqueCollectionsSales", unique_collectors_total as "uniqueCollectorsTotal"
209+
FROM `
210+
.append(MARKETPLACE_SQUID_SCHEMA)
211+
.append(
212+
SQL`.accounts_day_data
213+
WHERE `
214+
.append(where)
215+
.append(
216+
SQL`
217+
ORDER BY ${orderBy}`.append(orderDirection).append(SQL`
204218
LIMIT ${MAX_RESULTS}
205219
OFFSET ${MAX_RESULTS * page}
206220
`)
221+
)
222+
)
207223
}
208224

209225
// Collectors
@@ -212,20 +228,36 @@ export function getCollectorsDayDataQuery(filters: RankingsFilters, page = 0) {
212228

213229
return filters.from === 0
214230
? SQL`
215-
SELECT id, purchases, spent, unique_and_mythic_items, creators_supported_total
216-
FROM accounts
217-
WHERE `.append(where).append(SQL`
218-
ORDER BY ${orderBy} ${orderDirection}
231+
SELECT id, purchases, spent, unique_and_mythic_items as "uniqueAndMythicItems", creators_supported_total as "creatorsSupportedTotal"
232+
FROM `
233+
.append(MARKETPLACE_SQUID_SCHEMA)
234+
.append(
235+
SQL`.accounts
236+
WHERE `
237+
.append(where)
238+
.append(
239+
SQL`
240+
ORDER BY ${orderBy} `.append(orderDirection).append(SQL`
219241
${filters.first ? SQL`LIMIT ${filters.first}` : SQL``}
220242
`)
243+
)
244+
)
221245
: SQL`
222-
SELECT id, purchases, spent, unique_and_mythic_items, creators_supported_total
223-
FROM accounts_day_data
224-
WHERE `.append(where).append(SQL`
225-
ORDER BY ${orderBy} ${orderDirection}
246+
SELECT id, purchases, spent, unique_and_mythic_items as "uniqueAndMythicItems", creators_supported_total as "creatorsSupportedTotal"
247+
FROM `
248+
.append(MARKETPLACE_SQUID_SCHEMA)
249+
.append(
250+
SQL`.accounts_day_data
251+
WHERE `
252+
.append(where)
253+
.append(
254+
SQL`
255+
ORDER BY ${orderBy} `.append(orderDirection).append(SQL`
226256
LIMIT ${MAX_RESULTS}
227257
OFFSET ${MAX_RESULTS * page}
228258
`)
259+
)
260+
)
229261
}
230262

231263
export function sortRankResults(

0 commit comments

Comments
 (0)