Skip to content

send follow immediately #1091

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

Merged
merged 1 commit into from
May 11, 2025
Merged

Conversation

alphatownsman
Copy link
Member

No description provided.

Copy link

@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.

Hello @alphatownsman, 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!

Summary of Changes

This pull request introduces changes to the Follow model and related utilities to manage the state of follow requests more effectively. It adds new fields to the Follow model, specifically state_next_attempt and state_locked_until, and modifies the update_follow_state and follow methods to use a centralized Takahe.update_state method for updating the state of various objects, including Follow objects. This change ensures consistency when updating the state of follow requests.

Highlights

  • Model Changes: Adds state_next_attempt and state_locked_until fields to the Follow model in takahe/models.py and the corresponding migration file takahe/migrations/0001_initial.py.
  • State Management: Refactors update_follow_state and Takahe.follow in takahe/utils.py to use Takahe.update_state for updating the state of Follow objects, promoting consistency.
  • Centralized State Update: Extends Takahe.update_state in takahe/utils.py to handle Follow objects, centralizing state update logic for various models.

Changelog

  • takahe/migrations/0001_initial.py
    • Added state_next_attempt field as a DateTimeField with blank=True and null=True (line 916).
    • Added state_locked_until field as a DateTimeField with blank=True, null=True, and db_index=True (lines 918-920).
  • takahe/models.py
    • Added state_next_attempt field as a DateTimeField with blank=True and null=True (line 893).
    • Added state_locked_until field as a DateTimeField with null=True, blank=True, and db_index=True (line 894).
  • takahe/utils.py
    • Modified update_follow_state to use Takahe.update_state for updating the follow state (line 262).
    • Modified Takahe.follow to use Takahe.update_state when the follow state is not 'accepted' (line 270).
    • Updated Takahe.update_state to include Follow objects in the object type annotation (line 694).
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 is currently in preview and 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 to provide feedback.

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.


A follow's state,
A change of time it does await,
Locked until then.

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

@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 introduces new fields to the Follow model and updates the update_state function to include the Follow model. It also modifies the update_follow_state and follow methods in Takahe to use the update_state function. Overall, the changes seem reasonable, but there are a few points that need clarification and improvement.

Summary of Findings

  • Missing documentation for new fields: The pull request adds state_next_attempt and state_locked_until fields to the Follow model, but there is no documentation explaining their purpose or usage. This could make it difficult for other developers to understand and use these fields correctly.
  • Potential race condition in update_state: The update_state function updates the state_changed field to timezone.now(). If multiple instances try to update the state at the same time, there could be a race condition, leading to lost updates. Consider using auto_now=True in the model definition or using F expressions to avoid race conditions.

Merge Readiness

The pull request introduces important changes related to follow state management. While the code seems functional, the lack of documentation for the new fields and the potential race condition in update_state need to be addressed before merging. I am unable to approve this pull request, and recommend that it not be merged until those issues are addressed (at a minimum). Please have others review and approve this code before merging.

Comment on lines 695 to 697
):
obj.state = state
obj.state_changed = timezone.now()

Choose a reason for hiding this comment

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

high

Consider using F expressions to update state_changed to avoid potential race conditions if multiple instances try to update the state at the same time. Alternatively, using auto_now=True in the model definition would automatically update the timestamp on each save.

from django.db.models import F

        obj.state = state
        obj.state_changed = timezone.now()
        obj.state_changed = F('state_changed') # add this line
        obj.save()

Comment on lines +893 to +894
state_next_attempt = models.DateTimeField(blank=True, null=True)
state_locked_until = models.DateTimeField(null=True, blank=True, db_index=True)

Choose a reason for hiding this comment

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

medium

Consider adding verbose names and help texts to these fields in the model definition as well. This will improve the self-documenting nature of the code.

@alphatownsman alphatownsman merged commit 1d2d23e into neodb-social:main May 11, 2025
3 checks passed
@alphatownsman alphatownsman deleted the follow branch May 11, 2025 14:00
@github-project-automation github-project-automation bot moved this from Wishlist to Completed in NeoDB Roadmap May 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

1 participant