Skip to content

Updated handling for stats page audience filters#22571

Merged
9larsons merged 1 commit intomainfrom
fix-tb-audience-filter
Mar 19, 2025
Merged

Updated handling for stats page audience filters#22571
9larsons merged 1 commit intomainfrom
fix-tb-audience-filter

Conversation

@9larsons
Copy link
Contributor

ref https://linear.app/ghost/issue/ANAL-144/

  • reverted previous change
  • updated data files to use simpler aggregate fn

Type errors from the query params have been worked around by using a simpler aggregate function that should also be more performant. Still more to learn here - so far my understanding is this change is both appropriate and better, and at least works for the moment.

ref https://linear.app/ghost/issue/ANAL-144/
- reverted previous change
- updated data files to use simpler aggregate fn

Type errors from the query params have been worked around by using a simpler aggregate function that should also be more performant. Still more to learn here - so far my understanding is this change is both appropriate and better, and at least works for the moment.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 19, 2025

Walkthrough

This pull request introduces several version updates and schema adjustments across multiple files. In the Ghost admin utility (ghost/admin/app/utils/stats.js), the constant TB_VERSION is incremented from 0 to 1, and the getStatsParams function now converts the audience array into a comma-separated string before assigning it to params.member_status. Multiple datasource files under ghost/web-analytics/datasources now reflect a version bump from 0 to 1 and update the member_status field from using the conditional AggregateFunction(maxIf, String, UInt8) to a simpler SimpleAggregateFunction(max, String). Additionally, numerous pipe files in the ghost/web-analytics/pipes directory receive version number updates, and some SQL queries are modified to replace conditional aggregation functions (maxIfState) with simpler ones (maxSimpleState) when computing member_status.

Possibly related PRs

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/utils/stats.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)

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
  • @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.

@9larsons 9larsons changed the title Updated handling for audience filters Updated handling for stats page audience filters Mar 19, 2025
Copy link
Contributor

@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: 0

🧹 Nitpick comments (2)
ghost/web-analytics/pipes/_parsed_hits.incl (1)

1-4: Version Declaration Update and TAGS Consistency
The version declaration has been updated to VERSION 1, which aligns with the overall branch update. Please verify that retaining TAGS "v0" is intentional and consistent with your versioning strategy.

ghost/web-analytics/pipes/api_top_locations.pipe (1)

1-4: Version and Aggregate Function Consistency
The version number has been updated to VERSION 1, and the query now uses functions like uniqMerge(visits) alongside countMerge(pageviews). Ensure that using uniqMerge(visits) (as opposed to, for example, uniq(session_id) in other parts) is the desired approach for simplifying aggregation. Consistency across similar queries is key to the expected audience filter handling improvements.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between dcab6a9 and cf61680.

📒 Files selected for processing (16)
  • ghost/admin/app/utils/stats.js (2 hunks)
  • ghost/web-analytics/datasources/_mv_pages.datasource (2 hunks)
  • ghost/web-analytics/datasources/_mv_sessions.datasource (1 hunks)
  • ghost/web-analytics/datasources/_mv_sources.datasource (2 hunks)
  • ghost/web-analytics/pipes/_hits.incl (1 hunks)
  • ghost/web-analytics/pipes/_parsed_hits.incl (1 hunks)
  • ghost/web-analytics/pipes/api_kpis.pipe (1 hunks)
  • ghost/web-analytics/pipes/api_top_browsers.pipe (1 hunks)
  • ghost/web-analytics/pipes/api_top_devices.pipe (1 hunks)
  • ghost/web-analytics/pipes/api_top_locations.pipe (1 hunks)
  • ghost/web-analytics/pipes/api_top_os.pipe (1 hunks)
  • ghost/web-analytics/pipes/api_top_pages.pipe (1 hunks)
  • ghost/web-analytics/pipes/api_top_sources.pipe (1 hunks)
  • ghost/web-analytics/pipes/mv_pages.pipe (2 hunks)
  • ghost/web-analytics/pipes/mv_sessions.pipe (2 hunks)
  • ghost/web-analytics/pipes/mv_sources.pipe (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Tinybird Tests (Web Analytics)
  • GitHub Check: Unit tests (Node 22.13.1)
  • GitHub Check: Unit tests (Node 20.11.1)
  • GitHub Check: Unit tests (Node 18.12.1)
  • GitHub Check: Admin tests - Chrome
🔇 Additional comments (21)
ghost/web-analytics/pipes/_hits.incl (1)

1-6: Consistent Version Bump and Inclusion Check
The version is now set to VERSION 1 and the file includes _parsed_hits.incl as expected. Ensure that the kept TAGS "v0" accurately reflects the intended tag version, and that no additional updates are needed with respect to the integration of audience filters.

ghost/web-analytics/pipes/api_top_browsers.pipe (1)

1-4: Version Update and SQL Template Verification
The file’s version update from 0 to 1 is applied correctly. The SQL query—with its Jinja templating for date ranges, member status, device, browser, and source filtering—appears to remain functionally intact. Please double-check that these aggregation and filtering functions are now properly simplified and resolving the previous type errors noted in ANAL-144.

ghost/web-analytics/pipes/api_top_os.pipe (1)

1-4: Version Increment Confirmation
Updating the version to VERSION 1 is consistent with the project-wide schema changes. The filtering and aggregation logic for operating systems remains unchanged, so please confirm through integration tests that the intended performance and type improvements are effective.

ghost/web-analytics/pipes/api_top_pages.pipe (1)

1-1: Version increment aligns with audience filter changes

This version update from 0 to 1 is part of the coordinated versioning across multiple files to support the new audience filtering approach.

ghost/web-analytics/pipes/api_top_devices.pipe (1)

1-1: Version increment aligns with audience filter changes

This version update from 0 to 1 is part of the coordinated versioning across multiple files to support the new audience filtering approach.

ghost/web-analytics/pipes/api_kpis.pipe (1)

1-1: Version increment aligns with audience filter changes

This version update from 0 to 1 is part of the coordinated versioning across multiple files to support the new audience filtering approach.

ghost/web-analytics/pipes/api_top_sources.pipe (1)

1-1: Version increment aligns with audience filter changes

This version update from 0 to 1 is part of the coordinated versioning across multiple files to support the new audience filtering approach.

ghost/admin/app/utils/stats.js (2)

3-3: Version increment supports the audience filter format change

This version bump to TB_VERSION aligns with the changes in the .pipe files and supports the modified audience filter handling.


186-188:

Details

✅ Verification successful

Good fix: Converting audience array to comma-separated string

This change resolves the type error mentioned in the PR description by converting the audience array to a comma-separated string format. This ensures that the member_status parameter is properly formatted for the endpoint and matches the updated SimpleAggregateFunction approach in the backend.


🏁 Script executed:

#!/bin/bash
# Description: Check if the revised audience handling is used consistently in the codebase

# Look for any other direct usage of member_status parameter 
rg -A 2 -B 2 "member_status" --type js

Length of output: 1521


Actionable Confirmation: Audience Array Conversion is Correct and Consistent

The change converting the audience array to a comma-separated string (via audience.join(',')) is correctly implemented. Verification confirms that:

  • The intended update in ghost/admin/app/utils/stats.js properly transforms the array into the required string format.
  • Other code references handling member_status (in both frontend and migration files) are consistent with this format expectation.

No further modifications are needed.

ghost/web-analytics/pipes/mv_pages.pipe (2)

1-1: Version increment is appropriate for schema changes

The version bump from 0 to 1 correctly reflects the significant change in the aggregation method for member_status.


21-21: Simplified aggregation logic for member_status

The change from conditional filtering (maxIfState with an IN condition) to a simple maximum (maxSimpleState) aligns well with the PR objective to simplify audience filter handling and resolve type errors. This more straightforward approach should improve query performance while maintaining the necessary functionality.

ghost/web-analytics/datasources/_mv_sources.datasource (2)

1-1: Version increment matches pipe file changes

The version bump to 1 properly aligns with the corresponding pipe file version changes, maintaining consistency across the system.


15-15: Schema update for simplified member_status aggregation

The change from AggregateFunction(maxIf, String, UInt8) to SimpleAggregateFunction(max, String) correctly updates the schema to match the simplified aggregation approach used in the pipe files. This ensures that the datasource definition is compatible with the new query implementation.

ghost/web-analytics/pipes/mv_sources.pipe (2)

1-1: Version increment consistent with related files

The version bump to 1 maintains consistency with the other pipe and datasource file changes in this PR.


21-21: Simplified aggregation in sessions subquery

The change from conditional filtering (maxIfState with member status IN conditions) to a simple maximum (maxSimpleState) appropriately simplifies the logic in the sessions subquery. This is consistent with the changes in other pipe files and supports the PR goal of simplifying audience filter handling.

ghost/web-analytics/datasources/_mv_pages.datasource (2)

1-1: Version increment for schema change

The version bump to 1 correctly reflects the schema modification and maintains consistency with other file changes in this PR.


16-16: Consistent schema update for member_status

The change from AggregateFunction(maxIf, String, UInt8) to SimpleAggregateFunction(max, String) properly updates the schema definition to match the simplified aggregation approach. This change is consistent with the other datasource updates and aligns with the pipe file query modifications.

ghost/web-analytics/pipes/mv_sessions.pipe (2)

1-1: Version increment reflects schema change.

The version number increment from 0 to 1 appropriately signals the structural change in how member status is aggregated. This follows good versioning practices when modifying data schemas.


14-14: Simplified member status aggregation improves filter handling.

The change from maxIfState (which likely had a condition filtering specific values) to maxSimpleState aligns with the PR objective of simplifying audience filters. This approach removes conditional filtering and should help resolve the type errors mentioned in the PR description.

Would you like to verify that this change works correctly with all possible member status values? If some values were previously being filtered out intentionally, you may want to ensure this change doesn't introduce unexpected behavior.

ghost/web-analytics/datasources/_mv_sessions.datasource (2)

1-1: Version increment properly tracks schema change.

The version number increment from 0 to 1 appropriately reflects the schema modification. This maintains consistency with the corresponding pipe file and follows good versioning practices.


9-9: Schema change supports simplified member status aggregation.

The modification of the member_status field type from AggregateFunction(maxIf, String, UInt8) to SimpleAggregateFunction(max, String) aligns with:

  1. The simplified aggregation in the pipe file
  2. The PR objective of resolving type errors with query parameters
  3. Potential performance improvements mentioned in the PR description

This change is an appropriate implementation of the stated PR goals for simplifying audience filter handling.

@9larsons 9larsons merged commit af67b04 into main Mar 19, 2025
22 checks passed
@9larsons 9larsons deleted the fix-tb-audience-filter branch March 19, 2025 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant