-
Notifications
You must be signed in to change notification settings - Fork 949
perf(activity): cache singleton pointers and avoid string concat in hot path #9997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -150,12 +150,13 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const | |||||||||
| const auto fileName = activity._fileAction == QStringLiteral("file_renamed") ? activity._renamedFile | ||||||||||
| : activity._file; | ||||||||||
| if (!fileName.isEmpty()) { | ||||||||||
| const auto folder = FolderMan::instance()->folder(activity._folder); | ||||||||||
| auto *folderMan = FolderMan::instance(); | ||||||||||
| const auto folder = folderMan->folder(activity._folder); | ||||||||||
|
|
||||||||||
| const QString relPath = folder ? folder->remotePathTrailingSlash() + fileName | ||||||||||
| : fileName; | ||||||||||
|
|
||||||||||
| const auto localFiles = FolderMan::instance()->findFileInLocalFolders(relPath, accountState->account()); | ||||||||||
| const auto localFiles = folderMan->findFileInLocalFolders(relPath, accountState->account()); | ||||||||||
|
|
||||||||||
| if (localFiles.isEmpty()) { | ||||||||||
| return QString(); | ||||||||||
|
|
@@ -180,11 +181,12 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const | |||||||||
|
|
||||||||||
| const auto getDisplayPath = [&activity, &accountState]() { | ||||||||||
| if (!activity._file.isEmpty()) { | ||||||||||
| const auto folder = FolderMan::instance()->folder(activity._folder); | ||||||||||
| auto *folderMan = FolderMan::instance(); | ||||||||||
| const auto folder = folderMan->folder(activity._folder); | ||||||||||
|
|
||||||||||
| QString relPath = folder ? folder->remotePathTrailingSlash() + activity._file : activity._file; | ||||||||||
|
|
||||||||||
| const auto localFiles = FolderMan::instance()->findFileInLocalFolders(relPath, accountState->account()); | ||||||||||
| const auto localFiles = folderMan->findFileInLocalFolders(relPath, accountState->account()); | ||||||||||
|
|
||||||||||
| if (localFiles.count() > 0) { | ||||||||||
| if (relPath.startsWith('/') || relPath.startsWith('\\')) { | ||||||||||
|
|
@@ -904,11 +906,10 @@ QVariant ActivityListModel::convertLinkToActionButton(const OCC::ActivityLink &a | |||||||||
|
|
||||||||||
| const auto isReplyIconApplicable = activityLink._verb == QStringLiteral("REPLY"); | ||||||||||
|
|
||||||||||
| const QString replyButtonPath = QStringLiteral("image://svgimage-custom-color/reply.svg"); | ||||||||||
|
|
||||||||||
| if (isReplyIconApplicable) { | ||||||||||
| activityLinkCopy._imageSource = QString(replyButtonPath + "/"); | ||||||||||
| activityLinkCopy._imageSourceHovered = QString(replyButtonPath + "/"); | ||||||||||
| const QString replyButtonPath = QStringLiteral("image://svgimage-custom-color/reply.svg/"); | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would be much better to use a string literal to generate a proper QString
Suggested change
|
||||||||||
| activityLinkCopy._imageSource = replyButtonPath; | ||||||||||
| activityLinkCopy._imageSourceHovered = replyButtonPath; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| return QVariant::fromValue(activityLinkCopy); | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -724,25 +724,26 @@ void User::slotRefresh() | |
| { | ||
| slotRefreshUserStatus(); | ||
|
|
||
| auto *account = _account.data(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if (checkPushNotificationsAreReady()) { | ||
| // we are relying on WebSocket push notifications - ignore refresh attempts from UI | ||
| slotRefreshActivities(); | ||
| _timeSinceLastCheck[_account.data()].invalidate(); | ||
| _timeSinceLastCheck[account].invalidate(); | ||
| return; | ||
| } | ||
|
|
||
| // QElapsedTimer isn't actually constructed as invalid. | ||
| if (!_timeSinceLastCheck.contains(_account.data())) { | ||
| _timeSinceLastCheck[_account.data()].invalidate(); | ||
| if (!_timeSinceLastCheck.contains(account)) { | ||
| _timeSinceLastCheck[account].invalidate(); | ||
| } | ||
| QElapsedTimer &timer = _timeSinceLastCheck[_account.data()]; | ||
| QElapsedTimer &timer = _timeSinceLastCheck[account]; | ||
|
|
||
| // Fetch Activities only if visible and if last check is longer than 15 secs ago | ||
| if (timer.isValid() && timer.elapsed() < NOTIFICATION_REQUEST_FREE_PERIOD) { | ||
| qCDebug(lcActivity) << "Do not check as last check is only secs ago: " << timer.elapsed() / 1000; | ||
| return; | ||
| } | ||
| if (_account.data() && _account.data()->isConnected()) { | ||
| if (account && account->isConnected()) { | ||
| slotRefreshActivities(); | ||
| slotRefreshNotifications(); | ||
| timer.start(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not make
FolderMan::instance()an inline function if we think this is overused and may lead to overhead ?would not increase code complexity