Skip to content

Commit 574343e

Browse files
committed
lazy load most app config values, store them as lazy too
Signed-off-by: Julien Veyssier <[email protected]>
1 parent e014041 commit 574343e

22 files changed

+112
-109
lines changed

lib/Cron/CleanupQuotaDb.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ protected function run($argument) {
3636
intval($this->appConfig->getValueString(
3737
Application::APP_ID,
3838
'quota_period',
39-
strval(Application::DEFAULT_QUOTA_PERIOD)
39+
strval(Application::DEFAULT_QUOTA_PERIOD),
40+
true,
4041
)),
4142
Application::DEFAULT_QUOTA_PERIOD
4243
)

lib/Migration/Version030102Date20241003155512.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array
3737
$value = $this->appConfig->getValueString(Application::APP_ID, $key);
3838
if ($value !== '') {
3939
$encryptedValue = $this->crypto->encrypt($value);
40-
$this->appConfig->setValueString(Application::APP_ID, $key, $encryptedValue);
40+
$this->appConfig->setValueString(Application::APP_ID, $key, $encryptedValue, lazy: true);
4141
}
4242
}
4343

lib/Migration/Version030103Date20241009172829.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array
3434
$value = $this->appConfig->getValueString(Application::APP_ID, $key);
3535
if ($value !== '') {
3636
$decryptedValue = $this->crypto->decrypt($value);
37-
$this->appConfig->setValueString(Application::APP_ID, $key, $decryptedValue, false, true);
37+
$this->appConfig->setValueString(Application::APP_ID, $key, $decryptedValue, true, true);
3838
}
3939
}
4040
}

lib/Service/OpenAiAPIService.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ public function createChatCompletion(
624624
* @return array|null
625625
*/
626626
private function getAdminExtraParams(string $configKey): ?array {
627-
$stringValue = $this->appConfig->getValueString(Application::APP_ID, $configKey);
627+
$stringValue = $this->appConfig->getValueString(Application::APP_ID, $configKey, lazy: true);
628628
if ($stringValue === '') {
629629
return null;
630630
}
@@ -838,8 +838,8 @@ public function requestSpeechCreation(
838838
*/
839839
public function getExpTextProcessingTime(): int {
840840
return $this->isUsingOpenAi()
841-
? intval($this->appConfig->getValueString(Application::APP_ID, 'openai_text_generation_time', strval(Application::DEFAULT_OPENAI_TEXT_GENERATION_TIME)))
842-
: intval($this->appConfig->getValueString(Application::APP_ID, 'localai_text_generation_time', strval(Application::DEFAULT_LOCALAI_TEXT_GENERATION_TIME)));
841+
? intval($this->appConfig->getValueString(Application::APP_ID, 'openai_text_generation_time', strval(Application::DEFAULT_OPENAI_TEXT_GENERATION_TIME), lazy: true))
842+
: intval($this->appConfig->getValueString(Application::APP_ID, 'localai_text_generation_time', strval(Application::DEFAULT_LOCALAI_TEXT_GENERATION_TIME), lazy: true));
843843
}
844844

845845
/**
@@ -851,9 +851,9 @@ public function updateExpTextProcessingTime(int $runtime): void {
851851
$newTime = (1.0 - Application::EXPECTED_RUNTIME_LOWPASS_FACTOR) * $oldTime + Application::EXPECTED_RUNTIME_LOWPASS_FACTOR * floatval($runtime);
852852

853853
if ($this->isUsingOpenAi()) {
854-
$this->appConfig->setValueString(Application::APP_ID, 'openai_text_generation_time', strval(intval($newTime)));
854+
$this->appConfig->setValueString(Application::APP_ID, 'openai_text_generation_time', strval(intval($newTime)), lazy: true);
855855
} else {
856-
$this->appConfig->setValueString(Application::APP_ID, 'localai_text_generation_time', strval(intval($newTime)));
856+
$this->appConfig->setValueString(Application::APP_ID, 'localai_text_generation_time', strval(intval($newTime)), lazy: true);
857857
}
858858
}
859859

@@ -862,8 +862,8 @@ public function updateExpTextProcessingTime(int $runtime): void {
862862
*/
863863
public function getExpImgProcessingTime(): int {
864864
return $this->isUsingOpenAi()
865-
? intval($this->appConfig->getValueString(Application::APP_ID, 'openai_image_generation_time', strval(Application::DEFAULT_OPENAI_IMAGE_GENERATION_TIME)))
866-
: intval($this->appConfig->getValueString(Application::APP_ID, 'localai_image_generation_time', strval(Application::DEFAULT_LOCALAI_IMAGE_GENERATION_TIME)));
865+
? intval($this->appConfig->getValueString(Application::APP_ID, 'openai_image_generation_time', strval(Application::DEFAULT_OPENAI_IMAGE_GENERATION_TIME), lazy: true))
866+
: intval($this->appConfig->getValueString(Application::APP_ID, 'localai_image_generation_time', strval(Application::DEFAULT_LOCALAI_IMAGE_GENERATION_TIME), lazy: true));
867867
}
868868

869869
/**
@@ -875,9 +875,9 @@ public function updateExpImgProcessingTime(int $runtime): void {
875875
$newTime = (1.0 - Application::EXPECTED_RUNTIME_LOWPASS_FACTOR) * $oldTime + Application::EXPECTED_RUNTIME_LOWPASS_FACTOR * floatval($runtime);
876876

877877
if ($this->isUsingOpenAi()) {
878-
$this->appConfig->setValueString(Application::APP_ID, 'openai_image_generation_time', strval(intval($newTime)));
878+
$this->appConfig->setValueString(Application::APP_ID, 'openai_image_generation_time', strval(intval($newTime)), lazy: true);
879879
} else {
880-
$this->appConfig->setValueString(Application::APP_ID, 'localai_image_generation_time', strval(intval($newTime)));
880+
$this->appConfig->setValueString(Application::APP_ID, 'localai_image_generation_time', strval(intval($newTime)), lazy: true);
881881
}
882882
}
883883

0 commit comments

Comments
 (0)