Skip to content

Commit 83137a1

Browse files
authored
remove lru cache (#4865)
* remove lru cache * fix types issue * mypy
1 parent be66f8d commit 83137a1

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

backend/onyx/connectors/google_drive/doc_conversion.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from onyx.connectors.google_drive.section_extraction import HEADING_DELIMITER
2020
from onyx.connectors.google_utils.resources import get_drive_service
2121
from onyx.connectors.google_utils.resources import get_google_docs_service
22+
from onyx.connectors.google_utils.resources import GoogleDocsService
2223
from onyx.connectors.google_utils.resources import GoogleDriveService
2324
from onyx.connectors.models import ConnectorFailure
2425
from onyx.connectors.models import Document
@@ -36,7 +37,6 @@
3637
from onyx.file_processing.extract_file_text import xlsx_to_text
3738
from onyx.file_processing.file_validation import is_valid_image_type
3839
from onyx.file_processing.image_utils import store_image_and_create_section
39-
from onyx.utils.lazy import lazy_eval
4040
from onyx.utils.logger import setup_logger
4141
from onyx.utils.variable_functionality import (
4242
fetch_versioned_implementation_with_fallback,
@@ -146,7 +146,9 @@ def _download_and_extract_sections_basic(
146146

147147
# For other file types, download the file
148148
# Use the correct API call for downloading files
149-
response_call = lazy_eval(lambda: download_request(service, file_id))
149+
# lazy evaluation to only download the file if necessary
150+
def response_call() -> bytes:
151+
return download_request(service, file_id)
150152

151153
# Process based on mime type
152154
if mime_type == "text/plain":
@@ -418,13 +420,14 @@ def _convert_drive_item_to_document(
418420
Main entry point for converting a Google Drive file => Document object.
419421
"""
420422
sections: list[TextSection | ImageSection] = []
423+
421424
# Only construct these services when needed
422-
drive_service = lazy_eval(
423-
lambda: get_drive_service(creds, user_email=retriever_email)
424-
)
425-
docs_service = lazy_eval(
426-
lambda: get_google_docs_service(creds, user_email=retriever_email)
427-
)
425+
def _get_drive_service() -> GoogleDriveService:
426+
return get_drive_service(creds, user_email=retriever_email)
427+
428+
def _get_docs_service() -> GoogleDocsService:
429+
return get_google_docs_service(creds, user_email=retriever_email)
430+
428431
doc_id = "unknown"
429432

430433
try:
@@ -438,14 +441,14 @@ def _convert_drive_item_to_document(
438441
try:
439442
# get_document_sections is the advanced approach for Google Docs
440443
doc_sections = get_document_sections(
441-
docs_service=docs_service(),
444+
docs_service=_get_docs_service(),
442445
doc_id=file.get("id", ""),
443446
)
444447
if doc_sections:
445448
sections = cast(list[TextSection | ImageSection], doc_sections)
446449
if any(SMART_CHIP_CHAR in section.text for section in doc_sections):
447450
basic_sections = _download_and_extract_sections_basic(
448-
file, drive_service(), allow_images
451+
file, _get_drive_service(), allow_images
449452
)
450453
sections = align_basic_advanced(basic_sections, doc_sections)
451454

@@ -470,7 +473,7 @@ def _convert_drive_item_to_document(
470473
# If we don't have sections yet, use the basic extraction method
471474
if not sections:
472475
sections = _download_and_extract_sections_basic(
473-
file, drive_service(), allow_images
476+
file, _get_drive_service(), allow_images
474477
)
475478

476479
# If we still don't have any sections, skip this file

backend/onyx/utils/lazy.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)