-
Notifications
You must be signed in to change notification settings - Fork 37
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
502 the stats are not working #506
Conversation
WalkthroughThe pull request introduces changes to the statistics generation functionality in the backend. The Changes
Sequence DiagramsequenceDiagram
participant Controller as StatisticsController
participant Service as StatisticsService
participant Database as GuideLog Model
Controller->>Service: generateStatistics()
Service->>Database: Retrieve all logs
Database-->>Service: Return logs
Service->>Service: Process statistics
Service-->>Controller: Return generated statistics
The sequence diagram illustrates the new flow where statistics are generated without user-specific filtering, retrieving and processing logs for all users in a single operation. ✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 1
🔭 Outside diff range comments (1)
backend/src/service/statistics.service.js (1)
Line range hint
13-19
: Knees weak, arms are heavy - this query needs optimization! 🍝The database query could be optimized:
- The guideType filter is applied in memory rather than in the database query
- No limit on the number of records returned
Here's a suggested optimization:
const logs = await GuideLog.findAll({ where: { guideType: Number(guideType), showingTime: { [db.Sequelize.Op.gte]: twoMonthsAgo, }, }, + order: [['showingTime', 'DESC']], + limit: 1000, // Adjust based on your needs });
🧹 Nitpick comments (1)
backend/src/service/statistics.service.js (1)
Line range hint
22-33
: Vomit on his sweater already - this reduce needs cleanup! 🍝The reduce operation contains redundant guideType filtering that should be moved to the database query. Also, consider extracting the date comparison logic into a separate function for better readability.
+ const isInDateRange = (date, start, end) => date >= start && date < end; const { thisMonthViews, lastMonthViews } = logs.reduce( (acc, log) => { - if (log.guideType !== guideType) { - return acc; - } - if (log.showingTime >= thisMonth) { + if (isInDateRange(log.showingTime, thisMonth, now)) { acc.thisMonthViews += 1; - } else if (log.showingTime >= lastMonth) { + } else if (isInDateRange(log.showingTime, lastMonth, thisMonth)) { acc.lastMonthViews += 1; } return acc; }, { thisMonthViews: 0, lastMonthViews: 0 } );
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
backend/src/controllers/statistics.controller.js
(1 hunks)backend/src/service/statistics.service.js
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build (22.x)
🔇 Additional comments (1)
backend/src/controllers/statistics.controller.js (1)
7-7
: Yo dawg, we need to talk about security and performance! 🍝The removal of user filtering raises some concerns:
Security: This change makes all statistics visible to any authenticated user. Is this intentional? Consider adding role-based access control (RBAC) to restrict access to global statistics.
Performance: Processing all logs instead of a filtered subset could impact response times as the dataset grows.
Let's verify the potential performance impact with this script:
Perfect. Good to know. Thanks! |
Describe your changes
Statistics was fetching only the logs created by the logged user. To fix, I removed it and it will now display all the logs.
Issue number
#502
Please ensure all items are checked off before requesting a review: