Skip to content

Commit

Permalink
Use dbTyped in views.ts (#87)
Browse files Browse the repository at this point in the history
* Use dbTyped in views.ts

* Remove SOCKS_PROXY von docker-compose example
  • Loading branch information
Yasamato authored Dec 30, 2023
1 parent 2999757 commit f54fc29
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
3 changes: 0 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ services:

AUDIT_WEBHOOK: ${AUDIT_WEBHOOK}

# SOCKS5 Proxy for pinging
SOCKS_PROXY: ${SOCKS_PROXY}

# OAuth2
DISCORD_CLIENT_ID: ${DISCORD_CLIENT_ID}
DISCORD_CLIENT_SECRET: ${DISCORD_CLIENT_SECRET}
Expand Down
19 changes: 5 additions & 14 deletions lib/db/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { getLibraries } from './libraries'
import { singularToPlural } from '../utils'
import { Types } from '../../types/Components'
import { findOneTyped } from './dbTyped'

export async function getViews() {
return await getAll('views')
Expand All @@ -30,18 +31,11 @@ export async function getLastViews(type: Types, n: number) {
// count what has been popular recently
let accumulated = {}

if (type === Types.library) {
const libs = await getLibraries()
libs.forEach((lib) => {
accumulated[lib._id] = 0
})
}

data.forEach((d) => {
if (accumulated[d.contentId]) {
accumulated[d.contentId] += 1
if (accumulated[d._id]) {
accumulated[d._id] += 1
} else {
accumulated[d.contentId] = 1
accumulated[d._id] = 1
}
})

Expand All @@ -56,10 +50,7 @@ export async function getLastViews(type: Types, n: number) {
return (
await Promise.all(
sorted.map(async (s) => {
const data = await findOne(
singularToPlural(type),
type === Types.user ? { uid: s.contentId } : { _id: s.contentId }
)
const data = await findOneTyped(type, s.contentId)

data.views = s.count
return data
Expand Down

0 comments on commit f54fc29

Please sign in to comment.