Skip to content

Commit b4adfd2

Browse files
feat: dns caching manager (#1294)
* feat(dns): implement dns caching * feat: simple implementation of dnscaching * feat: dynamic ttl which is revalidated while using stale dns cache This is done as tmdb ttl is very less like 40 seconds so to make sure any issues wont be caused due to cached dns (previously we were caching for 5 minutes no matter what ttl) * feat(dns): improve DNS cache with multi-strategy fallback system - multiple DNS resolution strategie - graceful fallbacks between IPv6 and IPv4 addresses - network error reporting in fetch fix - compatibility with cypress testing (I HOPE) * fix: typos * feat: dns cache stats in jobs & cache page (and cleanup) * feat(networksettings): cache dns off by default * feat: make dnsCache optional and enable-able through network settings * chore(i18n): extract translation keys * test(cypress): fix cypress testing * feat(dnscache): dns cache entries are now flushable * style(cypress): run prettier * chore(cypresssettings): git ignore cypress json settings * chore: ignore cypress/config/settings.json * fix(dnscache): use entry specific hits and misses not global * refactor: clean up console logs * fix(dnscache): fix miss counter * feat(dnscache): global stats * chore(i18n): extract translation keys * refactor: use date-fns for formatting age and remove useless code * refactor: remove cypress testing options in dnsCacheManager * refactor: remove console logs * refactor: removed useless condition when its always truthy * fix: remove FetchAPI-related code * fix: remove old ipv4first setting * refactor: use our own dns-caching package instead * fix: correct dns-caching module configuration * fix: correct dns-caching module configuration * fix: remove useless lru-cache dependency * fix: update dns-caching to v0.2.0 * fix: add env variable for min/max ttl & update dns-caching * fix: update dns-caching package * fix: add force min/max TTL in network settings * docs: add docs for dns caching --------- Co-authored-by: Gauthier <[email protected]>
1 parent 5c1583c commit b4adfd2

File tree

16 files changed

+641
-118
lines changed

16 files changed

+641
-118
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ dist/
44
config/
55
CHANGELOG.md
66
pnpm-lock.yaml
7+
cypress/config/settings.cypress.json
78

89
# assets
910
src/assets/

.prettierrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,11 @@ module.exports = {
2121
rangeEnd: 0, // default: Infinity
2222
},
2323
},
24+
{
25+
files: 'cypress/config/settings.cypress.json',
26+
options: {
27+
rangeEnd: 0,
28+
},
29+
},
2430
],
2531
};

cypress/config/settings.cypress.json

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"apiKey": "testkey",
77
"applicationTitle": "Jellyseerr",
88
"applicationUrl": "",
9-
"csrfProtection": false,
109
"cacheImages": false,
1110
"defaultPermissions": 32,
1211
"defaultQuotas": {
@@ -180,5 +179,26 @@
180179
"image-cache-cleanup": {
181180
"schedule": "0 0 5 * * *"
182181
}
182+
},
183+
"network": {
184+
"csrfProtection": false,
185+
"trustProxy": false,
186+
"forceIpv4First": false,
187+
"dnsServers": "",
188+
"proxy": {
189+
"enabled": false,
190+
"hostname": "",
191+
"port": 8080,
192+
"useSsl": false,
193+
"user": "",
194+
"password": "",
195+
"bypassFilter": "",
196+
"bypassLocalAddresses": true
197+
},
198+
"dnsCache": {
199+
"enabled": false,
200+
"forceMinTtl": 0,
201+
"forceMaxTtl": -1
202+
}
183203
}
184204
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: DNS Caching
3+
description: Configure DNS caching settings.
4+
sidebar_position: 7
5+
---
6+
7+
# DNS Caching
8+
9+
Jellyseerr uses DNS caching to improve performance and reduce the number of DNS lookups required for external API calls. This can help speed up response times and reduce load on DNS servers, when something like a Pi-hole is used as a DNS resolver.
10+
11+
## Configuration
12+
13+
You can enable the DNS caching settings in the Network tab of the Jellyseerr settings. The default values follow the standard DNS caching behavior.
14+
15+
- **Force Minimum TTL**: Set a minimum time-to-live (TTL) in seconds for DNS cache entries. This ensures that frequently accessed DNS records are cached for a longer period, reducing the need for repeated lookups. Default is 0.
16+
- **Force Maximum TTL**: Set a maximum time-to-live (TTL) in seconds for DNS cache entries. This prevents infrequently accessed DNS records from being cached indefinitely, allowing for more up-to-date information to be retrieved. Default is -1 (unlimited).

docs/using-jellyseerr/settings/jobs&cache.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: Jobs & Cache
33
description: Configure jobs and cache settings.
4+
sidebar_position: 6
45
---
56

67
# Jobs & Cache

jellyseerr-api.yml

Lines changed: 120 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,51 @@ components:
260260
csrfProtection:
261261
type: boolean
262262
example: false
263+
forceIpv4First:
264+
type: boolean
265+
example: false
263266
trustProxy:
264267
type: boolean
265-
example: true
268+
example: false
269+
proxy:
270+
type: object
271+
properties:
272+
enabled:
273+
type: boolean
274+
example: false
275+
hostname:
276+
type: string
277+
example: ''
278+
port:
279+
type: number
280+
example: 8080
281+
useSsl:
282+
type: boolean
283+
example: false
284+
user:
285+
type: string
286+
example: ''
287+
password:
288+
type: string
289+
example: ''
290+
bypassFilter:
291+
type: string
292+
example: ''
293+
bypassLocalAddresses:
294+
type: boolean
295+
example: true
296+
dnsCache:
297+
type: object
298+
properties:
299+
enabled:
300+
type: boolean
301+
example: false
302+
forceMinTtl:
303+
type: number
304+
example: 0
305+
forceMaxTtl:
306+
type: number
307+
example: -1
266308
PlexLibrary:
267309
type: object
268310
properties:
@@ -2967,6 +3009,68 @@ paths:
29673009
imageCount:
29683010
type: number
29693011
example: 123
3012+
dnsCache:
3013+
type: object
3014+
properties:
3015+
stats:
3016+
type: object
3017+
properties:
3018+
size:
3019+
type: number
3020+
example: 1
3021+
maxSize:
3022+
type: number
3023+
example: 500
3024+
hits:
3025+
type: number
3026+
example: 19
3027+
misses:
3028+
type: number
3029+
example: 1
3030+
failures:
3031+
type: number
3032+
example: 0
3033+
ipv4Fallbacks:
3034+
type: number
3035+
example: 0
3036+
hitRate:
3037+
type: number
3038+
example: 0.95
3039+
entries:
3040+
type: array
3041+
additionalProperties:
3042+
type: object
3043+
properties:
3044+
addresses:
3045+
type: object
3046+
properties:
3047+
ipv4:
3048+
type: number
3049+
example: 1
3050+
ipv6:
3051+
type: number
3052+
example: 1
3053+
activeAddress:
3054+
type: string
3055+
example: 127.0.0.1
3056+
family:
3057+
type: number
3058+
example: 4
3059+
age:
3060+
type: number
3061+
example: 10
3062+
ttl:
3063+
type: number
3064+
example: 10
3065+
networkErrors:
3066+
type: number
3067+
example: 0
3068+
hits:
3069+
type: number
3070+
example: 1
3071+
misses:
3072+
type: number
3073+
example: 1
29703074
apiCaches:
29713075
type: array
29723076
items:
@@ -3006,6 +3110,21 @@ paths:
30063110
responses:
30073111
'204':
30083112
description: 'Flushed cache'
3113+
/settings/cache/dns/{dnsEntry}/flush:
3114+
post:
3115+
summary: Flush a specific DNS cache entry
3116+
description: Flushes a specific DNS cache entry
3117+
tags:
3118+
- settings
3119+
parameters:
3120+
- in: path
3121+
name: dnsEntry
3122+
required: true
3123+
schema:
3124+
type: string
3125+
responses:
3126+
'204':
3127+
description: 'Flushed dns cache'
30093128
/settings/logs:
30103129
get:
30113130
summary: Returns logs

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"cronstrue": "2.23.0",
5858
"date-fns": "2.29.3",
5959
"dayjs": "1.11.7",
60+
"dns-caching": "^0.2.4",
6061
"email-templates": "12.0.1",
6162
"email-validator": "2.0.4",
6263
"express": "4.21.2",

0 commit comments

Comments
 (0)