Was about to do some performance optimization of the hot paths in the item querying logic in the widget then I noticed something:
|
export const getDashboardData = () => { |
|
return axios |
|
.get(url('/notes/dashboard')) |
|
.then(response => { |
|
return response.data |
|
}) |
|
.catch(err => { |
|
console.error(err) |
|
handleSyncError(t('notes', 'Fetching notes for dashboard has failed.'), err) |
|
throw err |
|
}) |
|
} |
The dashboard widget is registered through DashboardWidget, but the rendered frontend still uses the old controller endpoint via the JS dashboard app. So DashboardWidget is not the sole implementation; it is the integration point, while NotesController::dashboard() is the data backend for the actual dashboard UI.
So we have two divergent implementations:
|
#[NoAdminRequired] |
|
public function dashboard() : JSONResponse { |
|
return $this->helper->handleErrorResponse(function () { |
|
$maxItems = 6; |
|
$userId = $this->helper->getUID(); |
|
$notes = $this->notesService->getTopNotes($userId); |
|
$hasMoreNotes = count($notes) > $maxItems; |
|
$notes = array_slice($notes, 0, $maxItems); |
|
$items = array_map(function ($note) { |
|
$excerpt = ''; |
|
try { |
|
$excerpt = $note->getExcerpt(); |
|
} catch (\Throwable $e) { |
|
} |
|
return [ |
|
'id' => $note->getId(), |
|
'title' => $note->getTitle(), |
|
'category' => $note->getCategory(), |
|
'favorite' => $note->getFavorite(), |
|
'excerpt' => $excerpt, |
|
]; |
|
}, $notes); |
|
return [ |
|
'items' => $items, |
|
'hasMoreItems' => $hasMoreNotes, |
|
]; |
|
}); |
|
} |
|
|
|
public function getWidgetButtons(string $userId): array { |
|
$buttons = [ |
|
new WidgetButton( |
|
WidgetButton::TYPE_NEW, |
|
$this->url->linkToRouteAbsolute('notes.page.createGet'), |
|
$this->l10n->t('Create new note') |
|
) |
|
]; |
|
if ($this->notesService->countNotes($userId) > 7) { |
|
$buttons[] = new WidgetButton( |
|
WidgetButton::TYPE_MORE, |
|
$this->url->linkToRouteAbsolute('notes.page.index'), |
|
$this->l10n->t('More notes') |
|
); |
|
} |
|
return $buttons; |
|
} |
|
|
|
public function getItems(string $userId, ?string $since = null, int $limit = 7): array { |
|
$notes = $this->notesService->getTopNotes($userId); |
|
$notes = array_slice($notes, 0, $limit); |
|
return array_values(array_map(function (Note $note): WidgetItem { |
|
$excerpt = ''; |
|
try { |
|
$excerpt = $note->getExcerpt(); |
|
} catch (\Throwable $e) { |
|
} |
|
$link = $this->url->linkToRouteAbsolute('notes.page.indexnote', ['id' => $note->getId()]); |
|
$icon = $note->getFavorite() |
|
? $this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.svg')) |
|
: $this->getIconUrl(); |
|
return new WidgetItem($note->getTitle(), $excerpt, $link, $icon, (string)$note->getModified()); |
|
}, $notes)); |
|
} |
Was about to do some performance optimization of the hot paths in the item querying logic in the widget then I noticed something:
notes/src/NotesService.js
Lines 63 to 74 in 91912ec
The dashboard widget is registered through
DashboardWidget, but the rendered frontend still uses the old controller endpoint via the JS dashboard app. SoDashboardWidgetis not the sole implementation; it is the integration point, whileNotesController::dashboard()is the data backend for the actual dashboard UI.So we have two divergent implementations:
notes/lib/Controller/NotesController.php
Lines 114 to 142 in 91912ec
notes/lib/AppInfo/DashboardWidget.php
Lines 80 to 113 in 91912ec