Skip to content

T2976 Timeline ordering bugs and letters ordering bugs#281

Open
Shayan105 wants to merge 27 commits into14.0from
T2976-Timeline-ordering-bugs-and-letters-ordering-bugs
Open

T2976 Timeline ordering bugs and letters ordering bugs#281
Shayan105 wants to merge 27 commits into14.0from
T2976-Timeline-ordering-bugs-and-letters-ordering-bugs

Conversation

@Shayan105
Copy link
Member

@Shayan105 Shayan105 commented Feb 9, 2026

Summary

This PR solves two bugs:

  1. In the /letters page although the order of the letters is correct, the displayed date is wrong (it's still the create_date).
  2. In the timeline, the "A picture arrived" is inconsistent. For ex. a sponsorship can start after receiving the picture.

Problem 1

Except from updating the view, another logic is important to add.
When the letter is from the supporter to the beneficiary (S->B) then the effective date to be shown to the user is the create_date (first time the letter entered the system).

Note to Mr @ecino :
Although in the following PR you requested to use status_date only, there is a drawback in this situation. Basing the ordering of the letters S->B in the status_date can be confusing to the sponsors as this field is changing at every step of the processing of the letter. I recommend using create_date when the direction is S->B.

Problem 2

The timeline order of the picture was based on the create_date of the picture instead of taking into accoun the date the sponsor was notified by a partner_communicaiton_job "New Biennial".

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Shayan105, 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 addresses critical display and ordering issues within the application. It rectifies the incorrect date presentation and sorting logic for letters on the dedicated letters page, ensuring a more intuitive user experience. Concurrently, it modernizes the timeline's handling of child pictures by transitioning to a notification-based system for biennial photos, which are then intelligently linked to their corresponding images.

Highlights

  • Letter Ordering and Date Display Fix: Corrected the ordering and displayed dates for letters on the /letters page. Beneficiary-to-Supporter letters now use status_date and Supporter-to-Beneficiary letters use create_date for sorting and display, resolving the issue where only create_date was used.
  • Timeline Picture Handling Refactor: Updated the child timeline to integrate 'biennial photos' by tracking partner_communication_job notifications instead of direct compassion_child_pictures records. A post-processing step now matches these notifications to the most relevant actual child picture for display.
  • Improved Letter Filtering: Enhanced the filtering for Supporter-to-Beneficiary letters to exclude those in 'Exception' or 'Quality check unsuccessful' states, ensuring only valid letters are presented.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • my_compassion/controllers/my2_children.py
    • Updated docstrings for timeline functions to reflect the inclusion of 'biennial photos'.
    • Modified SQL queries in _get_timeline_count and _get_timeline_data to count and fetch partner_communication_job records for 'New Biennial' communications instead of direct compassion_child_pictures.
    • Adjusted child_id parameter handling in SQL execution to support both string (for LIKE matching) and integer (for column selection) types.
    • Implemented post-processing logic in _get_timeline_data to search for and attach the picture_id of the most relevant compassion.child.pictures record to each child_picture_notification.
  • my_compassion/controllers/my2_letters.py
    • Modified the letter filtering domain to exclude Supporter-to-Beneficiary letters with 'Exception' or 'Quality check unsuccessful' states.
    • Removed database-level ordering for letters and introduced Python-based sorting logic.
    • Implemented conditional sorting for letters: Beneficiary-to-Supporter letters are sorted by status_date, and Supporter-to-Beneficiary letters are sorted by create_date.
  • my_compassion/templates/components/my2_sponsor_child_timeline_batch.xml
    • Updated the template to render child_picture_notification items instead of child_picture.
    • Modified image links (t-att-href) to use item['picture_id'] for displaying biennial photos, aligning with the new backend logic.
  • my_compassion/templates/pages/my2_child_letters.xml
    • Adjusted the t-att-data-create_date attribute for letter cards to conditionally display letter.status_date for Beneficiary-to-Supporter letters and letter.create_date for others, fixing the displayed date bug.
Activity
  • The pull request was created by Shayan105 to address two specific bugs: incorrect date display on the /letters page and general timeline ordering issues.
  • The changes in my2_letters.py directly tackle the letter date and ordering problem by implementing conditional sorting and filtering.
  • The modifications across my2_children.py and my2_sponsor_child_timeline_batch.xml indicate a refactoring of how child pictures are represented and displayed on the timeline, moving towards a notification-centric approach for biennial photos.
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

This pull request addresses ordering and data display bugs in the timeline and letters pages. The changes for the timeline correctly integrate biennial photos by replacing the old child pictures logic, though the SQL queries could be optimized for better performance. For the letters page, the sorting logic is corrected to use different date fields based on the letter's direction, but this is done in Python after fetching all records, which introduces a significant performance risk. Additionally, the domain filter for letters has a critical syntax error that needs to be fixed. Finally, the fix for displaying the correct letter date in the UI is incomplete. My review includes suggestions to address these performance and correctness issues.

Shayan105 and others added 2 commits February 9, 2026 15:57
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@Shayan105
Copy link
Member Author

/gemini review

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

This pull request addresses two bugs related to ordering in the timeline and letters pages. The logic for timeline events for new pictures is now based on the partner communication job date, which is a good fix for the inconsistency. The letter sorting logic is also updated to use different date fields based on the letter's direction.

My review focuses on several key areas. I've identified a critical performance issue in the letter sorting implementation, which loads all records into memory instead of using database-level sorting and pagination. I've provided a suggestion to fix this using a SQL CASE statement. I also found a medium-severity performance concern in the timeline picture matching logic and suggested a more scalable approach. Finally, I've pointed out an inconsistency in SQL queries for maintainability. Addressing these points will improve the performance, scalability, and consistency of the code.

Copy link
Contributor

@NoeBerdoz NoeBerdoz left a comment

Choose a reason for hiding this comment

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

As discussed, let's simplify the picture part handling to be based on the create_date

@Shayan105 Shayan105 closed this Feb 12, 2026
@Shayan105 Shayan105 reopened this Feb 12, 2026
@Shayan105
Copy link
Member Author

@NoeBerdoz Changes applied.
Thanks for the review

@Shayan105 Shayan105 requested a review from NoeBerdoz February 12, 2026 10:05
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.

2 participants