Skip to content

fix(user,sync): resolve trailing slash profile break and daily sync timezone mismatch#316

Open
RishiSingh13 wants to merge 1 commit into
codepvg:mainfrom
RishiSingh13:fix/trailing-slash-and-timezone
Open

fix(user,sync): resolve trailing slash profile break and daily sync timezone mismatch#316
RishiSingh13 wants to merge 1 commit into
codepvg:mainfrom
RishiSingh13:fix/trailing-slash-and-timezone

Conversation

@RishiSingh13

@RishiSingh13 RishiSingh13 commented Jul 12, 2026

Copy link
Copy Markdown

Description

This Pull Request addresses two bugs to improve URL routing resilience and synchronization accuracy:

  1. User Profile URL Resolution: Resolves a bug where visiting a profile page using a URL with a trailing slash (e.g., /user/someusername/) completely breaks the page's graphs, headings, and API fetches.
  2. Synchronization Timezone Inconsistency: Fixes an issue where UTC conversion during yesterday's date generation causes comparison snapshots to target the wrong date depending on what hour of the morning the sync job executes.

Linked Issues

Fixes #315

Changes Made

1. Frontend Profile Page URL Handling

  • File: frontend/js/user/historical-graphs.js
  • Before: currentUsername was fetched using pathSegments[pathSegments.length - 1]. If the URL had a trailing slash, it retrieved "" (empty string) as the username, triggering 404s when fetching /api/user/ and leaving the page graphs completely blank.
  • After: Modified the extraction to fall back to the second-to-last segment if the last one is empty:
    const currentUsername =
      pathSegments[pathSegments.length - 1] ||
      pathSegments[pathSegments.length - 2];

This brings the script in line with the fallback patterns already successfully implemented in badges.js and contest.js.

  1. Local Time Snapshot Date Generation
    File: scripts/sync-leaderboard.js
    Before: getYesterdaySnapshot() extracted targetDate using d.toISOString().split("T")[0]. During early morning sync runs (e.g., 3:00 AM IST), this UTC conversion rolled the date back a second day, causing the script to fetch a snapshot from two days ago.
    After: Constructed the local date format manually to bypass UTC shifts, aligning the logic with getFileName() inside the same script:
    javascript

const year = d.getFullYear();
const month = String(d.getMonth() + 1).padStart(2, "0");
const date = String(d.getDate()).padStart(2, "0");
const targetDate = ${year}-${month}-${date};
Type of Change
Bug fix
New feature
UI/Visual update
Documentation update
Refactor
Testing
Tested locally
Tested on mobile viewport (if applicable)
No console errors introduced
Local Testing Steps:
Visited http://localhost:3000/user/jagdish/ (with trailing slash) and verified that the Performance profile page load was successful, page heading resolved properly, and graphs rendered correctly without any console errors.
Ran node scripts/sync-leaderboard.js to ensure the sync pipeline runs without execution issues.
Formatted the codebase locally using npx prettier --write . prior to making commits.
Checklist
My code follows the project's coding style
I have formatted my code locally by running npx prettier --write . before submitting
I am submitting my PR from a dedicated fix/trailing-slash-and-timezone branch, not the main branch
I have performed a self-review of my code
My changes generate no new warnings or errors
I have updated documentation if required
I have linked the relevant issue

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for submitting a pull request.

Please ensure your changes comply with the project's contribution guidelines and that all workflow checks pass successfully.

Formatting and Branching

  • Please confirm you have formatted your code locally using npx prettier --write . before requesting a review.
  • Ensure this PR is made from a feature/* branch and not main.

Note: This project is currently maintained by a solo maintainer, so reviews and responses may sometimes take a little time. Thanks for your patience.

@RishiSingh13

Copy link
Copy Markdown
Author

@jagdish-15 i have raised a issue#315 and this was its fix and be assured i have checked everything working great . pls review this and merge it .
Thanx :)

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.

[Bug] Timezone mismatch in daily sync script causes incorrect rank change stats

1 participant