add debug mode (controls caches) and max cache time limits.

- add coeur config debugMode
  - currently controls if set the cache time in inline queries
  - can be enabled by `--debug-run`
  - change old `--debug -d` startup param (which means enable debug logging) to `--verbose-logging --verbose`
  - set the new `--debug -d` as the combined of `--debug-run` and `--verbose-logging`
  - deprecated `--dbg`, currently, it still works as old behavior (like `--verbose`)
This commit is contained in:
A.C.Sukazyo Eyre 2024-02-18 18:32:01 +08:00
parent 966c4dfa92
commit 025f152417
Signed by: Eyre_S
GPG Key ID: C17CE40291207874
4 changed files with 55 additions and 6 deletions

View File

@ -8,7 +8,7 @@ object MornyConfiguration {
val MORNY_CODE_STORE = "https://github.com/Eyre-S/Coeur-Morny-Cono" val MORNY_CODE_STORE = "https://github.com/Eyre-S/Coeur-Morny-Cono"
val MORNY_COMMIT_PATH = "https://github.com/Eyre-S/Coeur-Morny-Cono/commit/%s" val MORNY_COMMIT_PATH = "https://github.com/Eyre-S/Coeur-Morny-Cono/commit/%s"
val VERSION = "2.0.0-alpha15" val VERSION = "2.0.0-alpha16"
val VERSION_DELTA: Option[String] = None val VERSION_DELTA: Option[String] = None
val CODENAME = "guanggu" val CODENAME = "guanggu"

View File

@ -102,12 +102,24 @@ public class MornyConfig {
public final boolean commandLoginRefresh; public final boolean commandLoginRefresh;
public final boolean commandLogoutClear; public final boolean commandLogoutClear;
/* ======================================= *
* system: inline queries *
* ======================================= */
public final int inlineQueryCacheTimeMax;
/* ======================================= * /* ======================================= *
* system: http server * * system: http server *
* ======================================= */ * ======================================= */
public final int httpPort; public final int httpPort;
/* ======================================= *
* system: debug flags *
* ======================================= */
public final boolean debugMode;
/* ======================================= * /* ======================================= *
* function: reporter * * function: reporter *
* ======================================= */ * ======================================= */
@ -172,6 +184,8 @@ public class MornyConfig {
this.medicationNotifyAt = prototype.medicationNotifyAt; this.medicationNotifyAt = prototype.medicationNotifyAt;
if (prototype.httpPort < 0 || prototype.httpPort > 65535) throw new CheckFailure.UnavailableHttpPort(); if (prototype.httpPort < 0 || prototype.httpPort > 65535) throw new CheckFailure.UnavailableHttpPort();
this.httpPort = prototype.httpPort; this.httpPort = prototype.httpPort;
this.debugMode = prototype.debugMode;
this.inlineQueryCacheTimeMax = prototype.inlineQueryCacheTimeMax;
} }
public static class CheckFailure extends RuntimeException { public static class CheckFailure extends RuntimeException {
@ -203,6 +217,8 @@ public class MornyConfig {
@Nonnull public ZoneOffset medicationTimerUseTimezone = ZoneOffset.UTC; @Nonnull public ZoneOffset medicationTimerUseTimezone = ZoneOffset.UTC;
@Nonnull public final Set<Integer> medicationNotifyAt = new HashSet<>(); @Nonnull public final Set<Integer> medicationNotifyAt = new HashSet<>();
public int httpPort = 30179; public int httpPort = 30179;
public boolean debugMode = false;
public int inlineQueryCacheTimeMax = 300;
} }

View File

@ -30,7 +30,16 @@ object ServerMain {
while (i < args.length) { while (i < args.length) {
args(i) match { args(i) match {
case "-d" | "--dbg" | "--debug" => Log.debug(true) case "-d" | "--debug" =>
Log.debug(true)
config.debugMode = true
case "--debug-run" =>
config.debugMode = true
case "--dbg" =>
Log.debug(true)
deprecatedArgs += "--dbg" -> "--verbose-logging"
case "--verbose-logging" | "--verbose" =>
Log.debug(true)
case "-t" | "--test" => mode_testRun = true case "-t" | "--test" => mode_testRun = true
case "--no-hello" | "-hf" | "--quiet" | "-q" => showHello = false case "--no-hello" | "-hf" | "--quiet" | "-q" => showHello = false
@ -110,10 +119,31 @@ object ServerMain {
| ${deprecatedArgs map((d, n) => s"$d : use $n instead") mkString "\n "} | ${deprecatedArgs map((d, n) => s"$d : use $n instead") mkString "\n "}
|""".stripMargin |""".stripMargin
if (Log debug) if (config.debugMode && Log.debug)
logger `warn`
"""Coeur Debug mode enabled.
|
| The debug log will be outputted, and caches will be disabled.
| It will cause much unnecessary performance cost, may caused extremely slow down on your bot.
| Make sure that you are not in production environment.
|
| Since 2.0.0, this mode is the combined of the two following options:
| --debug-run enable coeur debug mode, that will disabled all the caches.
| --verbose-logging enable the logger to output debug/trace logs."""
.stripMargin
else if (config.debugMode)
logger `warn`
"""Coeur Debug mode enabled.
|
| All the bot caches will be disabled.
| It will cause much unnecessary performance cost, may caused extremely slow down on your bot.
| Make sure that you are not in production environment."""
.stripMargin
else if (Log debug)
logger `warn` logger `warn`
"""Debug log output enabled. """Debug log output enabled.
| It may lower your performance, make sure that you are not in production environment.""" | It will output much more debug/trace logs, may lower your performance,
| so make sure that you are not in production environment."""
.stripMargin .stripMargin
if (mode_echoVersion) { if (mode_echoVersion) {

View File

@ -18,10 +18,13 @@ class MornyOnInlineQuery (using queryManager: MornyQueryManager) (using coeur: M
val results: List[InlineQueryUnit[?]] = queryManager `query` update val results: List[InlineQueryUnit[?]] = queryManager `query` update
var cacheTime = Int.MaxValue var cacheTime =
if (coeur.config.debugMode) 0
else coeur.config.inlineQueryCacheTimeMax
var isPersonal = InlineQueryUnit.defaults.IS_PERSONAL var isPersonal = InlineQueryUnit.defaults.IS_PERSONAL
val resultAnswers = ListBuffer[InlineQueryResult[?]]() val resultAnswers = ListBuffer[InlineQueryResult[?]]()
for (r <- results) { for (r <- results) {
if (!coeur.config.debugMode)
if (cacheTime > r.cacheTime) cacheTime = r.cacheTime if (cacheTime > r.cacheTime) cacheTime = r.cacheTime
if (r isPersonal) isPersonal = true if (r isPersonal) isPersonal = true
resultAnswers += r.result resultAnswers += r.result