Skip to content

Commit baeaf68

Browse files
authored
Make maxConcurrentReqs configurable (#1341)
1 parent 51b5485 commit baeaf68

File tree

5 files changed

+12
-5
lines changed

5 files changed

+12
-5
lines changed

nitter.example.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ proxy = "" # http/https url, SOCKS proxies are not supported
2828
proxyAuth = ""
2929
apiProxy = "" # nitter-proxy host, e.g. localhost:7000
3030
disableTid = false # enable this if cookie-based auth is failing
31+
maxConcurrentReqs = 2 # max requests at a time per session to avoid race conditions
3132

3233
# Change default preferences here, see src/prefs_impl.nim for a complete list
3334
[Preferences]

src/auth.nim

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ import std/[asyncdispatch, times, json, random, strutils, tables, packedsets, os
33
import types, consts
44
import experimental/parser/session
55

6-
# max requests at a time per session to avoid race conditions
7-
const
8-
maxConcurrentReqs = 2
9-
hourInSeconds = 60 * 60
6+
const hourInSeconds = 60 * 60
107

118
var
129
sessionPool: seq[Session]
1310
enableLogging = false
11+
# max requests at a time per session to avoid race conditions
12+
maxConcurrentReqs = 2
13+
14+
proc setMaxConcurrentReqs*(reqs: int) =
15+
if reqs > 0:
16+
maxConcurrentReqs = reqs
1417

1518
template log(str: varargs[string, `$`]) =
1619
echo "[sessions] ", str.join("")

src/config.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ proc getConfig*(path: string): (Config, parseCfg.Config) =
4242
proxy: cfg.get("Config", "proxy", ""),
4343
proxyAuth: cfg.get("Config", "proxyAuth", ""),
4444
apiProxy: cfg.get("Config", "apiProxy", ""),
45-
disableTid: cfg.get("Config", "disableTid", false)
45+
disableTid: cfg.get("Config", "disableTid", false),
46+
maxConcurrentReqs: cfg.get("Config", "maxConcurrentReqs", 2)
4647
)
4748

4849
return (conf, cfg)

src/nitter.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ setMaxHttpConns(cfg.httpMaxConns)
3939
setHttpProxy(cfg.proxy, cfg.proxyAuth)
4040
setApiProxy(cfg.apiProxy)
4141
setDisableTid(cfg.disableTid)
42+
setMaxConcurrentReqs(cfg.maxConcurrentReqs)
4243
initAboutPage(cfg.staticDir)
4344

4445
waitFor initRedisPool(cfg)

src/types.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ type
277277
proxyAuth*: string
278278
apiProxy*: string
279279
disableTid*: bool
280+
maxConcurrentReqs*: int
280281

281282
rssCacheTime*: int
282283
listCacheTime*: int

0 commit comments

Comments
 (0)