Skip to content

Commit 8be1b55

Browse files
committed
perf(quick-actions): eliminate dublicate api calld for each envelope
Signed-off-by: Hamza <hamzamahjoubi221@gmail.com>
1 parent adf81ed commit 8be1b55

File tree

7 files changed

+58
-22
lines changed

7 files changed

+58
-22
lines changed

lib/Controller/PageController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ public function index(): TemplateResponse {
238238
'quick-actions',
239239
$this->quickActionsService->findAll($this->currentUserId),
240240
);
241+
$this->initialStateService->provideInitialState(
242+
'quick-actions-processed',
243+
$this->quickActionsService->findAllProcessed($this->currentUserId),
244+
);
241245
$googleOauthclientId = $this->config->getAppValue(Application::APP_ID, 'google_oauth_client_id');
242246
if (!empty($googleOauthclientId)) {
243247
$this->initialStateService->provideInitialState(

lib/Db/Actions.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,22 @@
2222
class Actions extends Entity implements JsonSerializable {
2323
protected $name;
2424
protected $accountId;
25+
protected $actionSteps;
26+
protected $icon;
2527

2628
public function __construct() {
2729
$this->addType('name', 'string');
2830
$this->addType('accountId', 'integer');
31+
$this->addType('actionSteps', 'array');
32+
$this->addType('icon', 'string');
33+
}
34+
35+
public function setActionSteps(array $actionSteps): void {
36+
$this->actionSteps = $actionSteps;
37+
}
38+
39+
public function setIcon(string $icon): void {
40+
$this->icon = $icon;
2941
}
3042

3143
#[ReturnTypeWillChange]
@@ -34,6 +46,8 @@ public function jsonSerialize() {
3446
'id' => $this->getId(),
3547
'name' => $this->getName(),
3648
'accountId' => $this->getAccountId(),
49+
'actionSteps' => $this->actionSteps,
50+
'icon' => $this->icon,
3751

3852
];
3953
}

lib/Service/QuickActionsService.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ public function __construct(
4343
public function findAll(string $userId): array {
4444
return $this->actionsMapper->findAll($userId);
4545
}
46+
/**
47+
* @param string $userId
48+
* @return Actions[]
49+
*/
50+
public function findAllProcessed(string $userId): array {
51+
$actions = $this->actionsMapper->findAll($userId);
52+
foreach ($actions as $action) {
53+
$actionSteps = $this->actionStepMapper->findAllStepsForOneAction($action->getId(), $userId);
54+
$action->setActionSteps($actionSteps);
55+
$action->setIcon($actionSteps[0]->getName());
56+
}
57+
return $actions;
58+
}
4659

4760
/**
4861
* @throws DoesNotExistException
@@ -82,6 +95,10 @@ public function findAllActionSteps(int $actionId, string $userId): array {
8295
return $this->actionStepMapper->findAllStepsForOneAction($actionId, $userId);
8396
}
8497

98+
public function findAllActionStepsForUser(string $userId): array {
99+
return $this->actionStepMapper->findAllStepsForUser($userId);
100+
}
101+
85102
/**
86103
* @throws DoesNotExistException
87104
*/

src/components/Envelope.vue

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -765,16 +765,11 @@ export default {
765765
].filter(option => option.timestamp !== null)
766766
},
767767
},
768-
watch: {
769-
storeActions() {
770-
this.filterAndEnrichQuickActions()
771-
},
772-
},
773-
async mounted() {
768+
mounted() {
774769
this.onWindowResize()
775770
window.addEventListener('resize', this.onWindowResize)
776771
if (this.filteredQuickActions.length === 0) {
777-
await this.filterAndEnrichQuickActions()
772+
this.filterAndEnrichQuickActions()
778773
}
779774
},
780775
methods: {
@@ -787,37 +782,35 @@ export default {
787782
formatted() {
788783
return shortRelativeDatetime(new Date(this.data.dateInt * 1000))
789784
},
790-
async filterAndEnrichQuickActions() {
785+
filterAndEnrichQuickActions() {
791786
this.filteredQuickActions = []
792-
const quickActions = this.mainStore.getQuickActions().filter(action => action.accountId === this.data.accountId)
787+
const quickActions = this.mainStore.getQuickActionProcessed().filter(action => action.accountId === this.data.accountId)
793788
for (const action of quickActions) {
794-
const steps = await findAllStepsForAction(action.id)
795-
const check = steps.every(step => {
796-
if (['markAsSpam', 'applyTag', 'markAsImportant', 'markAsFavorite'].includes(step.type) && !this.hasWriteAcl) {
789+
const check = action.actionSteps.every(step => {
790+
if (['markAsSpam', 'applyTag', 'markAsImportant', 'markAsFavorite'].includes(step.name) && !this.hasWriteAcl) {
797791
return false
798792
}
799-
if (['markAsRead', 'markAsUnread'].includes(step.type) && !this.hasSeenAcl) {
793+
if (['markAsRead', 'markAsUnread'].includes(step.name) && !this.hasSeenAcl) {
800794
return false
801795
}
802-
if (['moveThread', 'deleteThread'].includes(step.type) && !this.hasDeleteAcl) {
796+
if (['moveThread', 'deleteThread'].includes(step.name) && !this.hasDeleteAcl) {
803797
return false
804798
}
805799
return true
806800
})
807-
if (check) {
808-
this.filteredQuickActions.push({
809-
...action,
810-
steps,
811-
icon: steps[0]?.name,
812-
})
813-
}
801+
if(check) {
802+
this.filteredQuickActions.push({
803+
...action,
804+
})
805+
}
806+
814807
}
815808
},
816809
async executeQuickAction(action) {
817810
this.closeQuickActionsMenu()
818811
this.quickActionLoading = true
819812
try {
820-
for (const step of action.steps) {
813+
for (const step of action.actionSteps) {
821814
switch (step.name) {
822815
case 'markAsSpam':
823816
await this.onToggleJunk()

src/init.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export default function initAfterAppCreation() {
8888
})
8989

9090
mainStore.setQuickActions(loadState('mail', 'quick-actions', []))
91+
mainStore.setQuickActionsProcessed(loadState('mail', 'quick-actions-processed', []))
9192

9293
const accountSettings = loadState('mail', 'account-settings')
9394
const accounts = loadState('mail', 'accounts', [])

src/store/mainStore.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export default defineStore('main', {
110110
myTextBlocks: [],
111111
sharedTextBlocks: [],
112112
quickActions: [],
113+
quickActionsProcessed: [],
113114
}
114115
},
115116
getters: {

src/store/mainStore/actions.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2372,6 +2372,9 @@ export default function mainStoreActions() {
23722372
setQuickActions(quickActions) {
23732373
this.quickActions = quickActions
23742374
},
2375+
setQuickActionsProcessed(quickActionsProcessed) {
2376+
this.quickActionsProcessed = quickActionsProcessed
2377+
},
23752378
patchQuickActionLocally(quickAction) {
23762379
const index = this.quickActions.findIndex(s => s.id === quickAction.id)
23772380
if (index !== -1) {
@@ -2493,5 +2496,8 @@ export default function mainStoreActions() {
24932496
getQuickActions() {
24942497
return this.quickActions
24952498
},
2499+
getQuickActionProcessed(){
2500+
return this.quickActionsProcessed
2501+
}
24962502
}
24972503
}

0 commit comments

Comments
 (0)