Decrease initial load on python package#513
Draft
Edwardvaneechoud wants to merge 1 commit into
Draft
Conversation
✅ Deploy Preview for flowfile-wasm canceled.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request refactors how and when the database is initialized throughout the codebase, making database setup explicit and lazy, rather than relying on import-time side effects. It introduces an
ensure_db_initialized()function that safely and idempotently initializes the database before any actual DB access, and updates all relevant code paths to use this function. Additionally, it delays heavy imports (such asdeltalakeand FastAPI-related modules) until they are actually needed, reducing import overhead for users of the dataframe API.Database Initialization Refactor:
ensure_db_initialized()inflowfile_core.database.connection, which lazily and safely runs Alembic migrations and seeds default rows before database access. This replaces import-time initialization and is now called in all DB accessors and main entry points. [1] [2] [3]ensure_db_initialized()before accessing the DB. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]flowfile_core.__init__andinit_db.py, so the DB is not created or migrated just by importing the core library. [1] [2] [3]Lazy Import Improvements:
requestsinflowfile.__init__by using a__getattr__hook, so importingflowfilefor dataframe functionality remains lightweight. [1] [2]deltalakeandpyarrow.datasetimports inside functions that actually use them, reducing import overhead and avoiding unnecessary dependencies for unrelated workflows. [1] [2] [3] [4] [5] [6] [7] [8]Exception Handling Consistency:
FlowfileHTTPExceptioninstead of FastAPI'sHTTPException, improving modularity and testability. [1] [2] [3]These changes make the codebase more modular, improve startup performance for non-server workflows, and ensure database migrations and seeding happen exactly when needed.