Skip to content
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

🐛 Fixed degraded database performance when using the Post Analytics screen #22031

Merged

Conversation

cmraible
Copy link
Collaborator

@cmraible cmraible commented Jan 21, 2025

ref https://linear.app/ghost/issue/ONC-717/support-escalation-re-dashboard-unresponsive

This reverts commit 9082a9f, which introduced an automatic refresh interval on the Post Analytics screen in Admin. This change led to an increase in the number of requests to the /ghost/api/admin/members/events/ endpoint, which is a particularly database intensive endpoint. Ultimately this led to significantly higher load on the database which degraded performance for sites with a large email_recipients table.

Copy link

coderabbitai bot commented Jan 21, 2025

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ghost/admin/app/components/posts/analytics.js

Oops! Something went wrong! :(

ESLint: 8.44.0

Error: Failed to load parser '@babel/eslint-parser' declared in 'ghost/admin/.eslintrc.js': Cannot find module '@babel/eslint-parser'
Require stack:

  • /ghost/admin/.eslintrc.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Function.resolve (node:internal/modules/helpers:145:19)
    at Object.resolve (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2346:46)
    at ConfigArrayFactory._loadParser (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3325:39)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3099:43)
    at _normalizeObjectConfigDataBody.next ()
    at ConfigArrayFactory._normalizeObjectConfigData (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3040:20)
    at _normalizeObjectConfigData.next ()
    at ConfigArrayFactory.loadInDirectory (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2886:28)
    at CascadingConfigArrayFactory._loadConfigInAncestors (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3871:46)

Walkthrough

The pull request modifies the post analytics component in Ghost's admin interface by removing automatic data refresh functionality and introducing a manual refresh button. The changes eliminate the periodic auto-refresh mechanism and replace it with a user-triggered refresh option. The modification shifts the control of data refreshing from an automatic background process to an explicit user action.

Changes

File Change Summary
ghost/admin/app/components/posts/analytics.hbs Added <GhTaskButton> for manual post analytics refresh
ghost/admin/app/components/posts/analytics.js Removed AUTO_REFRESH_RATE constant and autoRefreshTask method

Sequence Diagram

sequenceDiagram
    participant User
    participant PostAnalyticsComponent
    participant DataService

    User->>PostAnalyticsComponent: Click "Refresh" button
    PostAnalyticsComponent->>DataService: Fetch post analytics
    DataService-->>PostAnalyticsComponent: Return updated analytics data
    PostAnalyticsComponent-->>User: Display refreshed data
Loading

Poem

🐰 A Rabbit's Ode to Manual Refresh 🔄

No more ticking, no more auto-spin
A button's click shall data's journey begin
Refresh at will, control restored
Analytics dance when user's chord is scored!

Hop hop, refresh! 🚀

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@cmraible cmraible changed the title Revert "Auto trigger Post analytics refresh (#21930)" 🐛 Disabled Post Analytics auto refresh to reduce database load Jan 21, 2025
@cmraible cmraible marked this pull request as ready for review January 21, 2025 00:53
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
ghost/admin/app/components/posts/analytics.hbs (1)

38-45: LGTM! Manual refresh button implementation looks good.

The GhTaskButton implementation provides a clear way for users to manually refresh analytics data, replacing the auto-refresh functionality. The button includes appropriate visual feedback and maintains consistent styling.

Consider adding a tooltip to inform users about the manual refresh functionality, especially since this is a change in behavior from auto-refresh:

     <GhTaskButton
         @buttonText="Refresh"
         @task={{this.fetchPostTask}}
         @showIcon={{true}}
         @idleIcon="reload"
         @successText="Refreshed"
+        @title="Click to refresh analytics data"
         @class="gh-btn gh-btn-icon refresh"
         @successClass="gh-btn gh-btn-icon refresh" />
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cf9c019 and b0adf1e.

📒 Files selected for processing (2)
  • ghost/admin/app/components/posts/analytics.hbs (1 hunks)
  • ghost/admin/app/components/posts/analytics.js (1 hunks)
🔇 Additional comments (1)
ghost/admin/app/components/posts/analytics.js (1)

6-6: LGTM! Import cleanup looks good.

The import statement has been correctly updated to remove unused imports while maintaining required ones.

@@ -3,7 +3,7 @@ import DeletePostModal from '../modals/delete-post';
import PostSuccessModal from '../modal-post-success';
import anime from 'animejs/lib/anime.es.js';
import {action} from '@ember/object';
import {didCancel, task, timeout} from 'ember-concurrency';
import {didCancel, task} from 'ember-concurrency';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Error handling needs improvement for manual refresh

The current implementation only handles task cancellation errors silently and lacks proper error handling for API requests. Since users will now manually trigger refreshes, failed requests should be properly communicated.

  • Add proper error handling in fetchPostTask to show API errors to users
  • Add error handling for store queries in fetchPostCountTask
  • Add error notifications for failed API requests in _fetchReferrersStats
🔗 Analysis chain

Verify error handling for manual refresh.

Since we're moving from auto-refresh to manual refresh, ensure that error states are properly handled and communicated to users.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for error handling in fetchPostTask
ast-grep --pattern 'fetchPostTask() {
  $$$
  try {
    $$$
  } catch {
    $$$
  }
  $$$
}'

# Check for error notifications
rg -A 5 'notifications\.showAPIError|notifications\.error' ghost/admin/app/components/posts/analytics.js

Length of output: 201


Script:

#!/bin/bash
# Find the task implementation
ast-grep --pattern 'fetchPostTask = task(function* () {
  $$$
}'

# Look for alternative error handling patterns
rg -A 10 'catch\(' ghost/admin/app/components/posts/analytics.js

# Check for notification service injection
rg '@service notifications' ghost/admin/app/components/posts/analytics.js

# Look for any task error handling
rg -A 10 'task\(' ghost/admin/app/components/posts/analytics.js

Length of output: 303


Script:

#!/bin/bash
# Look for yield statements and task implementation
rg -A 10 'yield' ghost/admin/app/components/posts/analytics.js

# Check for notifications usage
rg 'this\.notifications' ghost/admin/app/components/posts/analytics.js

# Look for error-related code
rg -i 'error|fail|catch' ghost/admin/app/components/posts/analytics.js

Length of output: 3195

@cmraible cmraible changed the title 🐛 Disabled Post Analytics auto refresh to reduce database load 🐛 Disabled automatic refresh of Post Analytics to reduce database load Jan 21, 2025
@cmraible cmraible changed the title 🐛 Disabled automatic refresh of Post Analytics to reduce database load 🐛 Fixed increased database load from Post Analytics screen Jan 21, 2025
@cmraible cmraible changed the title 🐛 Fixed increased database load from Post Analytics screen 🐛 Fixed degraded database performance caused by the Post Analytics screen Jan 21, 2025
@cmraible cmraible changed the title 🐛 Fixed degraded database performance caused by the Post Analytics screen 🐛 Fixed degraded database performance caused by the Post Analytics page Jan 21, 2025
@cmraible cmraible changed the title 🐛 Fixed degraded database performance caused by the Post Analytics page 🐛 Fixed degraded database performance caused by the Post Analytics UI Jan 21, 2025
@cmraible cmraible changed the title 🐛 Fixed degraded database performance caused by the Post Analytics UI 🐛 Fixed degraded database performance caused by the Post Analytics screen Jan 21, 2025
@cmraible cmraible changed the title 🐛 Fixed degraded database performance caused by the Post Analytics screen 🐛 Fixed degraded database performance when using the Post Analytics screen Jan 21, 2025
@cmraible cmraible merged commit 6b00bde into main Jan 21, 2025
22 of 39 checks passed
@cmraible cmraible deleted the chris-onc-717-support-escalation-re-dashboard-unresponsive branch January 21, 2025 01:34
cmraible added a commit that referenced this pull request Jan 21, 2025
…creen (#22031)

ref
https://linear.app/ghost/issue/ONC-717/support-escalation-re-dashboard-unresponsive

This reverts commit 9082a9f, which
introduced an automatic refresh interval on the Post Analytics screen in
Admin. This change led to an increase in the number of requests to the
`/ghost/api/admin/members/events/` endpoint, which is a particularly
database intensive endpoint. Ultimately this led to significantly higher
load on the database which degraded performance for sites with a large
`email_recipients` table.
cmraible added a commit that referenced this pull request Jan 21, 2025
…creen (#22031)

ref
https://linear.app/ghost/issue/ONC-717/support-escalation-re-dashboard-unresponsive

This reverts commit 9082a9f, which
introduced an automatic refresh interval on the Post Analytics screen in
Admin. This change led to an increase in the number of requests to the
`/ghost/api/admin/members/events/` endpoint, which is a particularly
database intensive endpoint. Ultimately this led to significantly higher
load on the database which degraded performance for sites with a large
`email_recipients` table.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant