Selaa lähdekoodia

Make maxConcurrentReqs configurable (#1341)

jackyzy823 9 kuukautta sitten
vanhempi
commit
baeaf685d3
5 muutettua tiedostoa jossa 12 lisäystä ja 5 poistoa
  1. 1 0
      nitter.example.conf
  2. 7 4
      src/auth.nim
  3. 2 1
      src/config.nim
  4. 1 0
      src/nitter.nim
  5. 1 0
      src/types.nim

+ 1 - 0
nitter.example.conf

@@ -28,6 +28,7 @@ proxy = ""  # http/https url, SOCKS proxies are not supported
 proxyAuth = ""
 apiProxy = "" # nitter-proxy host, e.g. localhost:7000
 disableTid = false # enable this if cookie-based auth is failing
+maxConcurrentReqs = 2 # max requests at a time per session to avoid race conditions
 
 # Change default preferences here, see src/prefs_impl.nim for a complete list
 [Preferences]

+ 7 - 4
src/auth.nim

@@ -3,14 +3,17 @@ import std/[asyncdispatch, times, json, random, strutils, tables, packedsets, os
 import types, consts
 import experimental/parser/session
 
-# max requests at a time per session to avoid race conditions
-const
-  maxConcurrentReqs = 2
-  hourInSeconds = 60 * 60
+const hourInSeconds = 60 * 60
 
 var
   sessionPool: seq[Session]
   enableLogging = false
+  # max requests at a time per session to avoid race conditions
+  maxConcurrentReqs = 2
+
+proc setMaxConcurrentReqs*(reqs: int) =
+  if reqs > 0:
+    maxConcurrentReqs = reqs
 
 template log(str: varargs[string, `$`]) =
   echo "[sessions] ", str.join("")

+ 2 - 1
src/config.nim

@@ -42,7 +42,8 @@ proc getConfig*(path: string): (Config, parseCfg.Config) =
     proxy: cfg.get("Config", "proxy", ""),
     proxyAuth: cfg.get("Config", "proxyAuth", ""),
     apiProxy: cfg.get("Config", "apiProxy", ""),
-    disableTid: cfg.get("Config", "disableTid", false)
+    disableTid: cfg.get("Config", "disableTid", false),
+    maxConcurrentReqs: cfg.get("Config", "maxConcurrentReqs", 2)
   )
 
   return (conf, cfg)

+ 1 - 0
src/nitter.nim

@@ -39,6 +39,7 @@ setMaxHttpConns(cfg.httpMaxConns)
 setHttpProxy(cfg.proxy, cfg.proxyAuth)
 setApiProxy(cfg.apiProxy)
 setDisableTid(cfg.disableTid)
+setMaxConcurrentReqs(cfg.maxConcurrentReqs)
 initAboutPage(cfg.staticDir)
 
 waitFor initRedisPool(cfg)

+ 1 - 0
src/types.nim

@@ -277,6 +277,7 @@ type
     proxyAuth*: string
     apiProxy*: string
     disableTid*: bool
+    maxConcurrentReqs*: int
 
     rssCacheTime*: int
     listCacheTime*: int