listAllContracts: sort by createdTime by default

This commit is contained in:
mantikoros 2022-08-22 14:23:43 -05:00
parent 650aa68bcd
commit 3313b55853
2 changed files with 4 additions and 3 deletions

View File

@ -125,9 +125,10 @@ export async function listTaggedContractsCaseInsensitive(
export async function listAllContracts( export async function listAllContracts(
n: number, n: number,
before?: string before?: string,
sortDescBy = 'createdTime'
): Promise<Contract[]> { ): Promise<Contract[]> {
let q = query(contracts, orderBy('popularityScore', 'desc'), limit(n)) let q = query(contracts, orderBy(sortDescBy, 'desc'), limit(n))
if (before != null) { if (before != null) {
const snap = await getDoc(doc(contracts, before)) const snap = await getDoc(doc(contracts, before))
q = query(q, startAfter(snap)) q = query(q, startAfter(snap))

View File

@ -4,7 +4,7 @@ import { getServerSideSitemap, ISitemapField } from 'next-sitemap'
import { listAllContracts } from 'web/lib/firebase/contracts' import { listAllContracts } from 'web/lib/firebase/contracts'
export const getServerSideProps: GetServerSideProps = async (ctx) => { export const getServerSideProps: GetServerSideProps = async (ctx) => {
const contracts = await listAllContracts(1000, undefined) const contracts = await listAllContracts(1000, undefined, 'popularityScore')
const score = (popularity: number) => Math.tanh(Math.log10(popularity + 1)) const score = (popularity: number) => Math.tanh(Math.log10(popularity + 1))