Skip to content

fix for "Sync Past Entries" fails after changing an exercise #544"#697

Merged
CodeWithCJ merged 1 commit intomainfrom
dev
Feb 20, 2026
Merged

fix for "Sync Past Entries" fails after changing an exercise #544"#697
CodeWithCJ merged 1 commit intomainfrom
dev

Conversation

@CodeWithCJ
Copy link
Owner

fix for #544

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @CodeWithCJ, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request primarily focuses on fixing a critical bug that caused 'Sync Past Entries' to fail when an exercise was changed. The solution involved a significant refactoring of the exerciseService to ensure proper dependency management and consistent use of the exerciseRepository for exercise snapshot and review functionalities. Additionally, the PR enhances security by adding robust validation for the encryption key and includes general code cleanup and formatting improvements across the codebase.

Highlights

  • Bug Fix: Sync Past Entries: Resolved an issue where 'Sync Past Entries' would fail after an exercise was modified, ensuring data consistency for workout plans.
  • Code Refactoring and Dependency Management: Refactored exerciseService to consistently use exerciseRepository for operations related to exercise entry snapshots and review, addressing potential circular dependency issues and improving modularity. The exerciseService import in exerciseTemplate.js was also moved to prevent circular dependencies.
  • Security Enhancement: Added a critical check for the presence of the SPARKY_FITNESS_API_ENCRYPTION_KEY environment variable and improved error messaging for invalid key lengths in encryption.js, enhancing application security.
  • New Test File for Repository Verification: Introduced a new test file (exerciseRepository.test.js) to explicitly verify that the exerciseRepository correctly exposes essential functions for exercise snapshot updates and review, ensuring the integrity of the refactoring.
  • Configuration and Formatting Updates: Updated Docker Compose files with corrected secret variable comments and applied extensive code formatting across multiple JavaScript files for improved readability and maintainability.
Changelog
  • SparkyFitnessServer/models/exerciseTemplate.js
    • Moved exerciseService import inside a function to resolve a potential circular dependency.
    • Applied extensive code formatting for improved readability.
  • SparkyFitnessServer/security/encryption.js
    • Added a check to ensure the SPARKY_FITNESS_API_ENCRYPTION_KEY environment variable is set.
    • Improved the error message for encryption keys with invalid lengths.
  • SparkyFitnessServer/services/exerciseService.js
    • Refactored calls to getExercisesNeedingReview, updateExerciseEntriesSnapshot, and clearUserIgnoredUpdate to use exerciseRepository instead of exerciseDb.
    • Exported the logWorkoutPresetGrouped function.
    • Applied extensive code formatting, including line breaks and consistent string literal usage.
  • SparkyFitnessServer/tests/exerciseRepository.test.js
    • Added a new test file to verify that exerciseRepository correctly exports functions related to exercise snapshot and review.
  • SparkyFitnessServer/tests/test_secret_loader.js
    • Renamed to secretLoader.test.js for consistency.
  • docker/docker-compose.dev.yml
    • Updated comment for BETTER_AUTH_SECRET_FILE.
  • docker/docker-compose.prod.yml
    • Updated comment for BETTER_AUTH_SECRET_FILE.
Activity
  • No specific activity (comments, reviews, etc.) was provided in the context for this pull request.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request successfully addresses issue #544 by implementing exercise snapshotting during template synchronization and correcting repository method calls in the exercise service. It also improves system robustness with enhanced encryption key validation at startup and a repository verification test. However, the synchronization logic in exerciseTemplate.js introduces significant performance concerns due to redundant database queries and sequential processing within nested loops. Addressing these efficiency issues and adding safety checks for missing exercises will improve the reliability and scalability of the feature.

"info",
`createExerciseEntriesFromTemplate called for templateId: ${templateId}, userId: ${userId}`,
);
const exerciseService = require("../services/exerciseService");
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Requiring exerciseService inside the function is a workaround for a circular dependency between the model and service layers. While it prevents load-time issues, it indicates tight coupling. Consider refactoring the logic to move the synchronization orchestration to the service layer or using dependency injection to improve testability and maintainability.

Comment on lines +135 to +138
const setsResult = await client.query(
"SELECT * FROM workout_plan_assignment_sets WHERE assignment_id = $1",
[assignment.id],
);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Performing a database query for sets inside the nested loops will significantly degrade performance as the date range or number of assignments increases. Consider pre-fetching all sets for the template's assignments in a single query using WHERE assignment_id IN (...) before entering the date loop.

@CodeWithCJ CodeWithCJ merged commit 36ba721 into main Feb 20, 2026
6 checks passed
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