-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Fix multiple issues: export empty datasets, reset large data, geo-location tracking, and timezone consistency #3705
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?
Conversation
…ation tracking, and timezone consistency
|
@Ayush3603 is attempting to deploy a commit to the umami-software Team on Vercel. A member of the Team first needs to authorize it. |
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.
Greptile Overview
Greptile Summary
This PR attempts to fix 4 separate issues: empty dataset exports, large data resets, geo-location tracking, and timezone inconsistencies. While the export fix is well-implemented, the PR contains critical bugs that will prevent it from working correctly.
Key Changes
- Export Empty Datasets (Issue #3699): Checks if all datasets are empty before creating export, returns error response that triggers toast notification - WORKS CORRECTLY
- Reset Large Data (Issue #3698): Attempts batch deletion to avoid transaction timeouts - BROKEN: Prisma's
deleteManydoesn't supporttakeparameter - Geo-location Tracking (Issue #3701): Adds multiple fallback sources for country code - PROBLEMATIC: Uses continent code as country fallback
- Timezone Consistency (Issue #3700): Passes timezone to stats functions - INCOMPLETE: Misses
getRealtimeActivitycall
Critical Issues Found
-
Batch deletion won't work - The
resetWebsitefunction usesdeleteMany({ where, take: 10000 })but Prisma doesn't supporttakeindeleteMany. This means the timeout issue won't be fixed. -
Continent codes mixed with country codes - Using
result.continent?.codeas a fallback will store continent codes (AS, EU, etc.) as country codes, corrupting data. -
Incomplete timezone fix - Only 2 of 3 function calls in
getRealtimeDatareceive the timezone parameter.
Confidence Score: 1/5
- This PR contains critical bugs that will break functionality and corrupt data
- Score reflects one completely broken feature (batch deletion), one data corruption issue (continent codes), and one incomplete fix (timezone). Only the export fix works correctly. The PR will cause more problems than it solves.
- Critical attention required for
src/queries/prisma/website.ts(batch deletion broken) andsrc/lib/detect.ts(continent code issue). Also reviewsrc/queries/sql/getRealtimeData.tsfor incomplete timezone fix.
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| src/app/api/websites/[websiteId]/export/route.ts | 4/5 | Adds empty dataset check before export - implementation is correct and improves UX |
| src/components/input/ExportButton.tsx | 5/5 | Handles no_data error response with toast notification - clean implementation with proper error handling |
| src/lib/detect.ts | 2/5 | Attempts to fix geo-location tracking but incorrectly uses continent code as country fallback - critical logic error |
| src/queries/prisma/website.ts | 0/5 | Batch deletion implementation is broken - Prisma's deleteMany doesn't support take parameter, code won't work |
| src/queries/sql/getRealtimeData.ts | 3/5 | Partially fixes timezone inconsistency but misses getRealtimeActivity call |
Sequence Diagram
sequenceDiagram
participant User
participant ExportButton
participant ExportAPI
participant Metrics
participant Database
User->>ExportButton: Click Download
ExportButton->>ExportButton: setIsLoading(true)
ExportButton->>ExportAPI: GET /websites/{id}/export
ExportAPI->>Metrics: getEventMetrics()
Metrics->>Database: Query events
Database-->>Metrics: Return events
ExportAPI->>Metrics: getPageviewMetrics() x2
Metrics->>Database: Query pageviews
Database-->>Metrics: Return pageviews
ExportAPI->>Metrics: getSessionMetrics() x3
Metrics->>Database: Query sessions
Database-->>Metrics: Return sessions
ExportAPI->>ExportAPI: Check if all datasets empty
alt No data available
ExportAPI-->>ExportButton: {error: 'no_data'}
ExportButton->>ExportButton: Show toast notification
ExportButton->>ExportButton: setIsLoading(false)
else Data available
ExportAPI->>ExportAPI: Create ZIP with CSVs
ExportAPI-->>ExportButton: {zip: base64String}
ExportButton->>ExportButton: loadZip()
ExportButton->>User: Download ZIP file
ExportButton->>ExportButton: setIsLoading(false)
end
Note over ExportAPI,Database: Issue #3699 Fixed: Prevents empty exports
participant Client
participant DetectLib
participant MaxMind
Client->>DetectLib: Track pageview with IP
DetectLib->>DetectLib: Check if localhost
alt Not localhost
DetectLib->>DetectLib: Check provider headers
alt No provider headers
DetectLib->>MaxMind: Lookup IP
MaxMind-->>DetectLib: Return geo data
DetectLib->>DetectLib: Try country sources (country, registered_country, represented_country, continent)
alt Has country code
DetectLib-->>Client: Location data
else No country code
DetectLib-->>Client: null
end
else Has provider headers
DetectLib-->>Client: Location from headers
end
else Is localhost
DetectLib-->>Client: null
end
Note over DetectLib,MaxMind: Issue #3701: Multiple fallbacks for country
participant RealtimeAPI
participant StatsQueries
RealtimeAPI->>RealtimeAPI: Extract timezone from filters
RealtimeAPI->>StatsQueries: getRealtimeActivity(filters)
RealtimeAPI->>StatsQueries: getPageviewStats(statsFilters)
RealtimeAPI->>StatsQueries: getSessionStats(statsFilters)
StatsQueries-->>RealtimeAPI: Return stats with timezone
RealtimeAPI->>RealtimeAPI: Process and aggregate data
RealtimeAPI-->>User: Realtime data with consistent timezone
Note over RealtimeAPI,StatsQueries: Issue #3700: Timezone consistency
participant ResetAPI
participant PrismaClient
User->>ResetAPI: Reset website
ResetAPI->>PrismaClient: deleteInBatches(eventData)
loop Until deleted < 10000
PrismaClient->>Database: deleteMany with take: 10000
Database-->>PrismaClient: Deleted count
end
ResetAPI->>PrismaClient: deleteInBatches(sessionData)
ResetAPI->>PrismaClient: deleteInBatches(websiteEvent)
ResetAPI->>PrismaClient: deleteInBatches(session)
ResetAPI->>PrismaClient: Update website.resetAt
ResetAPI-->>User: Success
Note over ResetAPI,PrismaClient: Issue #3698: Batch deletion (BROKEN)
9 files reviewed, 3 comments
|
This looks great! But can you address the issues brought up by Greptile? |
|
Sure |
Fixes Multiple Issues
This PR addresses several open issues in the Umami project:
1. Issue #3699: 🧩 UX – Prevent exporting empty datasets & display a warning message
Problem: When there is no data available in the dashboard, clicking the "Download" button still triggers a file download, resulting in empty CSV files.
Solution:
{ error: 'no_data' }when no data is available2. Issue #3698: Cannot reset large data
Problem: Resetting websites with large amounts of data causes transaction timeouts with error: "A rollback cannot be executed on an expired transaction"
Solution:
3. Issue #3701: Geo-location tracking (Country) broken in v3.0
Problem: Country tracking showing "Unknown" for majority of visitors after upgrading to v3.0
Solution:
4. Issue #3700: Chart timezone is different from realtime page
Problem: Chart and realtime page showing data in different timezones
Solution:
Testing
Benefits
Fixes #3699
Fixes #3698
Fixes #3701
Fixes #3700