Skip to content

Commit 69977e4

Browse files
committed
perf: Only apply default settings when user is created or settings are requested
Signed-off-by: provokateurin <kate@provokateurin.de>
1 parent 32d0371 commit 69977e4

File tree

11 files changed

+60
-129
lines changed

11 files changed

+60
-129
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
/*! third party licenses: js/vendor.LICENSE.txt */
2-
import{r,a as h,o as d,w as l,b as u,e as _,h as E,t as c,f as m,F as S,i as N,v as L,j as g,c as b}from"./style-D4lbnCBQ.chunk.mjs";import{_ as v,t as n,N as A,c as y,v as D,a as I,s as w,l as M}from"./_plugin-vue_export-helper-BI95Xr-Q.chunk.mjs";import{N as k}from"./NcSettingsSection-93UQoiwe-Ca38RvSq.chunk.mjs";const s={EMAIL_SEND_OFF:0,EMAIL_SEND_HOURLY:1,EMAIL_SEND_3HOURLY:2,EMAIL_SEND_DAILY:3,EMAIL_SEND_WEEKLY:4},x={name:"AdminSettings",components:{NcCheckboxRadioSwitch:A,NcSettingsSection:k},data(){return{batchtime_options:[{text:n("notifications","Never"),value:s.EMAIL_SEND_OFF},{text:n("notifications","1 hour"),value:s.EMAIL_SEND_HOURLY},{text:n("notifications","3 hours"),value:s.EMAIL_SEND_3HOURLY},{text:n("notifications","1 day"),value:s.EMAIL_SEND_DAILY},{text:n("notifications","1 week"),value:s.EMAIL_SEND_WEEKLY}],config:M("notifications","config")}},methods:{t:n,async updateSettings(){try{const e=new FormData;e.append("batchSetting",this.config.setting_batchtime),e.append("soundNotification",this.config.sound_notification?"yes":"no"),e.append("soundTalk",this.config.sound_talk?"yes":"no"),await y.post(D("apps/notifications/api/v2/settings/admin"),e),I(n("notifications","Your settings have been updated."))}catch(e){w(n("notifications","An error occurred while updating your settings.")),console.error(e)}}}},U={for:"notify_setting_batchtime",class:"notification-frequency__label"},V=["value"];function Y(e,i,O,R,a,o){const f=r("NcCheckboxRadioSwitch"),p=r("NcSettingsSection");return d(),h(p,{name:o.t("notifications","Notifications defaults"),description:o.t("notifications","Configure the default notification settings for new users")},{default:l(()=>[u("p",null,[u("label",U,c(o.t("notifications","Send email reminders about unhandled notifications after:")),1),E(u("select",{id:"notify_setting_batchtime","onUpdate:modelValue":i[0]||(i[0]=t=>a.config.setting_batchtime=t),class:"notification-frequency__select",onChange:i[1]||(i[1]=t=>o.updateSettings())},[(d(!0),m(S,null,N(a.batchtime_options,t=>(d(),m("option",{key:t.value,value:t.value},c(t.text),9,V))),128))],544),[[L,a.config.setting_batchtime]])]),_(f,{modelValue:a.config.sound_notification,"onUpdate:modelValue":[i[2]||(i[2]=t=>a.config.sound_notification=t),o.updateSettings]},{default:l(()=>[g(c(o.t("notifications","Play sound when a new notification arrives")),1)]),_:1},8,["modelValue","onUpdate:modelValue"]),_(f,{modelValue:a.config.sound_talk,"onUpdate:modelValue":[i[3]||(i[3]=t=>a.config.sound_talk=t),o.updateSettings]},{default:l(()=>[g(c(o.t("notifications","Play sound when a call started (requires Nextcloud Talk)")),1)]),_:1},8,["modelValue","onUpdate:modelValue"])]),_:1},8,["name","description"])}const F=v(x,[["render",Y]]);b(F).mount("#notifications-admin-settings");
2+
import{r as _,a as h,o as d,w as l,b as u,e as r,h as E,t as c,f as m,F as S,i as N,v as L,j as g,c as b}from"./style-D4lbnCBQ.chunk.mjs";import{_ as v,t as n,N as A,c as y,v as D,a as I,s as w,l as M}from"./_plugin-vue_export-helper-BI95Xr-Q.chunk.mjs";import{N as k}from"./NcSettingsSection-93UQoiwe-Ca38RvSq.chunk.mjs";const s={EMAIL_SEND_OFF:0,EMAIL_SEND_HOURLY:1,EMAIL_SEND_3HOURLY:2,EMAIL_SEND_DAILY:3,EMAIL_SEND_WEEKLY:4},x={name:"AdminSettings",components:{NcCheckboxRadioSwitch:A,NcSettingsSection:k},data(){return{batchtime_options:[{text:n("notifications","Never"),value:s.EMAIL_SEND_OFF},{text:n("notifications","1 hour"),value:s.EMAIL_SEND_HOURLY},{text:n("notifications","3 hours"),value:s.EMAIL_SEND_3HOURLY},{text:n("notifications","1 day"),value:s.EMAIL_SEND_DAILY},{text:n("notifications","1 week"),value:s.EMAIL_SEND_WEEKLY}],config:M("notifications","config")}},methods:{t:n,async updateSettings(){try{const e=new FormData;e.append("batchSetting",this.config.setting_batchtime),e.append("soundNotification",this.config.sound_notification?"yes":"no"),e.append("soundTalk",this.config.sound_talk?"yes":"no"),await y.post(D("apps/notifications/api/v2/settings/admin"),e),I(n("notifications","Your settings have been updated."))}catch(e){w(n("notifications","An error occurred while updating your settings.")),console.error(e)}}}},U={for:"notify_setting_batchtime",class:"notification-frequency__label"},V=["value"];function Y(e,i,O,R,a,o){const f=_("NcCheckboxRadioSwitch"),p=_("NcSettingsSection");return d(),h(p,{name:o.t("notifications","Notifications defaults"),description:o.t("notifications","Configure the default notification settings")},{default:l(()=>[u("p",null,[u("label",U,c(o.t("notifications","Send email reminders about unhandled notifications after:")),1),E(u("select",{id:"notify_setting_batchtime","onUpdate:modelValue":i[0]||(i[0]=t=>a.config.setting_batchtime=t),class:"notification-frequency__select",onChange:i[1]||(i[1]=t=>o.updateSettings())},[(d(!0),m(S,null,N(a.batchtime_options,t=>(d(),m("option",{key:t.value,value:t.value},c(t.text),9,V))),128))],544),[[L,a.config.setting_batchtime]])]),r(f,{modelValue:a.config.sound_notification,"onUpdate:modelValue":[i[2]||(i[2]=t=>a.config.sound_notification=t),o.updateSettings]},{default:l(()=>[g(c(o.t("notifications","Play sound when a new notification arrives")),1)]),_:1},8,["modelValue","onUpdate:modelValue"]),r(f,{modelValue:a.config.sound_talk,"onUpdate:modelValue":[i[3]||(i[3]=t=>a.config.sound_talk=t),o.updateSettings]},{default:l(()=>[g(c(o.t("notifications","Play sound when a call started (requires Nextcloud Talk)")),1)]),_:1},8,["modelValue","onUpdate:modelValue"])]),_:1},8,["name","description"])}const F=v(x,[["render",Y]]);b(F).mount("#notifications-admin-settings");
33
//# sourceMappingURL=notifications-admin-settings.mjs.map

js/notifications-admin-settings.mjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/AppInfo/Application.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use OCA\Notifications\Capabilities;
1414
use OCA\Notifications\Listener\AddMissingIndicesListener;
1515
use OCA\Notifications\Listener\BeforeTemplateRenderedListener;
16-
use OCA\Notifications\Listener\PostLoginListener;
1716
use OCA\Notifications\Listener\UserCreatedListener;
1817
use OCA\Notifications\Listener\UserDeletedListener;
1918
use OCA\Notifications\Notifier\AdminNotifications;
@@ -24,7 +23,6 @@
2423
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
2524
use OCP\DB\Events\AddMissingIndicesEvent;
2625
use OCP\Notification\IManager;
27-
use OCP\User\Events\PostLoginEvent;
2826
use OCP\User\Events\UserCreatedEvent;
2927
use OCP\User\Events\UserDeletedEvent;
3028

@@ -47,7 +45,6 @@ public function register(IRegistrationContext $context): void {
4745
$context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class);
4846
$context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
4947
$context->registerEventListener(UserCreatedEvent::class, UserCreatedListener::class);
50-
$context->registerEventListener(PostLoginEvent::class, PostLoginListener::class);
5148
}
5249

5350
#[\Override]

lib/BackgroundJob/GenerateUserSettings.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use OCA\Notifications\Model\Settings;
1212
use OCA\Notifications\Model\SettingsMapper;
13-
use OCP\AppFramework\Db\DoesNotExistException;
1413
use OCP\AppFramework\Utility\ITimeFactory;
1514
use OCP\BackgroundJob\TimedJob;
1615
use OCP\IDBConnection;
@@ -47,15 +46,11 @@ protected function run($argument): void {
4746
return;
4847
}
4948

50-
try {
51-
$this->settingsMapper->getSettingsByUser($user->getUID());
52-
} catch (DoesNotExistException) {
53-
$settings = new Settings();
54-
$settings->setUserId($user->getUID());
55-
$settings->setNextSendTime(1);
56-
$settings->setBatchTime(Settings::EMAIL_SEND_3HOURLY);
49+
// Initializes the default settings
50+
$settings = $this->settingsMapper->getSettingsByUser($user->getUID());
51+
if ($settings->getLastSendId() === 0) {
5752
$settings->setLastSendId($maxId);
58-
$this->settingsMapper->insert($settings);
53+
$this->settingsMapper->update($settings);
5954
}
6055
});
6156
}

0 commit comments

Comments
 (0)