📦 Lazy init for Mongo and Chroma clients - #1
Merged
Conversation
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.
Πρόβλημα
Τα Mongo και Chroma clients δημιουργούνταν σε module import time. Κάθε
import routers.chatάνοιγε δικτυακή σύνδεση, οπότε τα tests και κάθεεργαλείο που απλώς κάνει import το app απαιτούσαν live υποδομή.
Αλλαγές
backend/utils/lazy.py(νέο): το_lazy_proxyμεταφέρθηκε verbatim απότο
llm/clients.pyκαι προστέθηκε_is_initialized(proxy), που διαβάζειτο cache attribute
_objμέσωobject.__getattribute__χωρίς ναπυροδοτεί το initialization.
llm/clients.py: πλέον μόνο import από το νέο module.db.py:_create_mongo_client/_get_dbπίσω από proxy.rag/vectorstore.py:_create_chroma_client/_create_chroma_collectionπίσω από proxy.
main.py: το close στο lifespan τρέχει μόνο αν το client έχει όντωςαρχικοποιηθεί.
tests/conftest.py:ANONYMIZED_TELEMETRY=Falseπριν από κάθε import.Επαλήθευση
import routers.chatχωρίς δίκτυο: OK.test_login_does_not_create_new_mongo_client: PASSED (local mongo:7 μεMONGODB_URIoverride).test_auth.py: 10/10 PASSED.Follow-up
Τα 11 tests σε
test_auth.py/test_rbac.pyπου απαιτούν live Mongoθέλουν mocked fixture - ξεχωριστό PR.