feat: clean messages table after run in flow_runner#8773
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe code updates the flow for clearing a user's state by explicitly querying and deleting all message records associated with the user's flows before deleting the flows themselves. It also adjusts the order of deletions, ensuring user records are deleted after associated variable records. Import statements are consolidated for clarity. Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant FlowRunner
participant DB
Caller->>FlowRunner: clear_user_state(user_id)
FlowRunner->>DB: Query flow IDs for user_id
DB-->>FlowRunner: Return flow IDs
FlowRunner->>DB: Delete MessageTable entries for flow IDs
FlowRunner->>DB: Delete Flow entries for user_id
FlowRunner->>DB: Delete Variable entries for user_id
FlowRunner->>DB: Delete User entry for user_id
FlowRunner-->>Caller: Completion
✨ Finishing Touches🧪 Generate Unit Tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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
|
ogabrielluiz
left a comment
There was a problem hiding this comment.
Thanks for all the help, @barnuri !
I'll aprove this but I feel like we could use an in memory db, maybe using a context manager in the database_service. That way we don't have to worry about cleaning anything up, but it probably won't be that simple
Pull Request is not mergeable
* feat: flow_runner cleanup messages table * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes * fix lint * lint * fix lint * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
* feat: flow_runner cleanup messages table * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes * fix lint * lint * fix lint * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
* feat: flow_runner cleanup messages table * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes * fix lint * lint * fix lint * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
* feat: flow_runner cleanup messages table * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes * fix lint * lint * fix lint * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This pull request introduces updates to the
FlowRunnerservice insrc/backend/base/langflow/services/flow/flow_runner.py. The changes focus on improving database query efficiency and enhancing the handling of flow-related data. The most important changes include importing additional database models, modifying theclear_user_statemethod to handle cascading deletions more effectively, and updating imports for better organization.Database query improvements:
src/backend/base/langflow/services/flow/flow_runner.py: Updated theclear_user_statemethod to first retrieve flow IDs associated with a user using aselectquery, then delete related entries inMessageTableandFlowbased on those IDs. This ensures cascading deletions are handled more efficiently.Import updates:
src/backend/base/langflow/services/flow/flow_runner.py: Addedselectto the imports fromsqlmodelto facilitate more efficient database queries.src/backend/base/langflow/services/flow/flow_runner.py: Consolidated imports fromlangflow.services.database.modelsto includeFlow,MessageTable,User, andVariable, improving code organization and readability.Summary by CodeRabbit