Skip to content

Commit a8806c1

Browse files
committed
Replace references to models by cleanups
1 parent 30d79c0 commit a8806c1

File tree

5 files changed

+14
-159
lines changed

5 files changed

+14
-159
lines changed

src/db/couchSetup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
import { ServerScope } from 'nano'
77

88
import { serverConfig } from '../serverConfig'
9+
import { couchApiKeysSetup } from './couchApiKeys'
910
import { devicesSetup } from './couchDevices'
1011
import { settingsSetup, syncedReplicators } from './couchSettings'
1112
import { usersSetup } from './couchUsers'

src/models/Device.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/models/User.ts

Lines changed: 0 additions & 124 deletions
This file was deleted.

src/price-script/checkPriceChanges.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import io from '@pm2/io'
22
import { MetricType } from '@pm2/io/build/main/services/metrics'
3+
import { ServerScope } from 'nano'
34

5+
import { devicesSetup } from '../db/couchDevices'
46
import { syncedSettings } from '../db/couchSettings'
7+
import { devicesByCurrencyHours } from '../db/couchUsers'
58
import { CurrencyThreshold } from '../models/CurrencyThreshold'
6-
import { Device } from '../models/Device'
7-
import { User } from '../models/User'
9+
import { Device } from '../types/pushTypes'
810
import { PushResult, PushSender } from '../util/pushSender'
911
import { fetchThresholdPrice } from './fetchThresholdPrices'
1012

@@ -23,7 +25,10 @@ export interface NotificationPriceChange {
2325
priceChange: number
2426
}
2527

26-
export async function checkPriceChanges(sender: PushSender): Promise<void> {
28+
export async function checkPriceChanges(
29+
connection: ServerScope,
30+
sender: PushSender
31+
): Promise<void> {
2732
// Sends a notification to devices about a price change
2833
async function sendNotification(
2934
thresholdPrice: NotificationPriceChange,
@@ -78,7 +83,7 @@ export async function checkPriceChanges(sender: PushSender): Promise<void> {
7883
deviceIds.push(deviceId)
7984
}
8085
}
81-
const tokenGenerator = deviceTokenGenerator(deviceIds)
86+
const tokenGenerator = deviceTokenGenerator(connection, deviceIds)
8287
let done = false
8388
let successCount = 0
8489
let failureCount = 0
@@ -126,14 +131,16 @@ export async function checkPriceChanges(sender: PushSender): Promise<void> {
126131
}
127132

128133
async function* deviceTokenGenerator(
134+
connection: ServerScope,
129135
deviceIds: string[]
130136
): AsyncGenerator<string[], string[]> {
131137
const tokenSet: Set<string> = new Set()
132138
let tokens: string[] = []
133139
let bookmark: string | undefined
134140
let done = false
141+
const dbDevices = connection.use<Device>(devicesSetup.name)
135142
while (!done) {
136-
const response = await Device.table.find({
143+
const response = await dbDevices.find({
137144
bookmark,
138145
selector: {
139146
_id: {

src/price-script/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async function main(): Promise<void> {
4242
runCounter.inc()
4343

4444
for (const sender of senders) {
45-
await checkPriceChanges(sender)
45+
await checkPriceChanges(connection, sender)
4646
}
4747
},
4848
60 * 1000 * syncedSettings.doc.priceCheckInMinutes,

0 commit comments

Comments
 (0)