mirror of https://github.com/Chocobozzz/PeerTube
fix(server/geo-ip): throttle db download
parent
5dd0721bee
commit
5dfa07adb5
|
@ -6,6 +6,7 @@ import { CONFIG } from '@server/initializers/config.js'
|
||||||
import { logger, loggerTagsFactory } from './logger.js'
|
import { logger, loggerTagsFactory } from './logger.js'
|
||||||
import { isBinaryResponse, peertubeGot } from './requests.js'
|
import { isBinaryResponse, peertubeGot } from './requests.js'
|
||||||
import { isArray } from './custom-validators/misc.js'
|
import { isArray } from './custom-validators/misc.js'
|
||||||
|
import { throttle } from 'lodash-es'
|
||||||
|
|
||||||
const lTags = loggerTagsFactory('geo-ip')
|
const lTags = loggerTagsFactory('geo-ip')
|
||||||
|
|
||||||
|
@ -15,6 +16,7 @@ export class GeoIP {
|
||||||
private countryReader: Reader<CountryResponse>
|
private countryReader: Reader<CountryResponse>
|
||||||
private cityReader: Reader<CityResponse>
|
private cityReader: Reader<CityResponse>
|
||||||
|
|
||||||
|
private readonly INIT_READERS_RETRY_INTERVAL = 1000 * 60 * 10 // 10 minutes
|
||||||
private readonly countryDBPath = join(CONFIG.STORAGE.BIN_DIR, 'dbip-country-lite-latest.mmdb')
|
private readonly countryDBPath = join(CONFIG.STORAGE.BIN_DIR, 'dbip-country-lite-latest.mmdb')
|
||||||
private readonly cityDBPath = join(CONFIG.STORAGE.BIN_DIR, 'dbip-city-lite-latest.mmdb')
|
private readonly cityDBPath = join(CONFIG.STORAGE.BIN_DIR, 'dbip-city-lite-latest.mmdb')
|
||||||
|
|
||||||
|
@ -26,7 +28,7 @@ export class GeoIP {
|
||||||
if (CONFIG.GEO_IP.ENABLED === false) return emptyResult
|
if (CONFIG.GEO_IP.ENABLED === false) return emptyResult
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.initReadersIfNeeded()
|
await this.initReadersIfNeededThrottle()
|
||||||
|
|
||||||
const countryResult = this.countryReader?.get(ip)
|
const countryResult = this.countryReader?.get(ip)
|
||||||
const cityResult = this.cityReader?.get(ip)
|
const cityResult = this.cityReader?.get(ip)
|
||||||
|
@ -135,6 +137,8 @@ export class GeoIP {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private readonly initReadersIfNeededThrottle = throttle(this.initReadersIfNeeded.bind(this), this.INIT_READERS_RETRY_INTERVAL)
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
static get Instance () {
|
static get Instance () {
|
||||||
|
|
Loading…
Reference in New Issue