MCPcopy
hub / github.com/coderamp-labs/gitingest / _check_s3_cache

Function _check_s3_cache

src/server/query_processor.py:46–136  ·  view source on GitHub ↗

Check if digest already exists on S3 and return response if found. Parameters ---------- query : IngestionQuery The parsed query object. input_text : str Original input text. max_file_size : int Maximum file size in KB. pattern_type : str Patt

(
    query: IngestionQuery,
    input_text: str,
    max_file_size: int,
    pattern_type: str,
    pattern: str,
    token: str | None,
)

Source from the content-addressed store, hash-verified

44
45
46async def _check_s3_cache(
47 query: IngestionQuery,
48 input_text: str,
49 max_file_size: int,
50 pattern_type: str,
51 pattern: str,
52 token: str | None,
53) -> IngestSuccessResponse | None:
54 """Check if digest already exists on S3 and return response if found.
55
56 Parameters
57 ----------
58 query : IngestionQuery
59 The parsed query object.
60 input_text : str
61 Original input text.
62 max_file_size : int
63 Maximum file size in KB.
64 pattern_type : str
65 Pattern type (include/exclude).
66 pattern : str
67 Pattern string.
68 token : str | None
69 GitHub token.
70
71 Returns
72 -------
73 IngestSuccessResponse | None
74 Response if file exists on S3, None otherwise.
75
76 """
77 if not is_s3_enabled():
78 return None
79
80 try:
81 # Use git ls-remote to get commit SHA without cloning
82 clone_config = query.extract_clone_config()
83 logger.info("Resolving commit for S3 cache check", extra={"repo_url": query.url})
84 query.commit = await resolve_commit(clone_config, token=token)
85 logger.info("Commit resolved successfully", extra={"repo_url": query.url, "commit": query.commit})
86
87 # Generate S3 file path using the resolved commit
88 s3_file_path = generate_s3_file_path(
89 source=query.url,
90 user_name=cast("str", query.user_name),
91 repo_name=cast("str", query.repo_name),
92 commit=query.commit,
93 subpath=query.subpath,
94 include_patterns=query.include_patterns,
95 ignore_patterns=query.ignore_patterns,
96 )
97
98 # Check if file exists on S3
99 if check_s3_object_exists(s3_file_path):
100 # File exists on S3, serve it directly without cloning
101 s3_url = _build_s3_url(s3_file_path)
102 query.s3_url = s3_url
103

Callers 1

process_queryFunction · 0.85

Calls 8

is_s3_enabledFunction · 0.90
resolve_commitFunction · 0.90
generate_s3_file_pathFunction · 0.90
check_s3_object_existsFunction · 0.90
_build_s3_urlFunction · 0.90
get_metadata_from_s3Function · 0.90
extract_clone_configMethod · 0.80

Tested by

no test coverage detected