refactor: extract should_include_path to utils module to resolve circular import between indexer and attachment_indexer
This commit is contained in:
parent
9e42fb072b
commit
fe3ffe5860
@ -4,7 +4,7 @@ from pathlib import Path
|
||||
from typing import Dict, List, Optional, Set
|
||||
import threading
|
||||
|
||||
from backend.indexer import _should_include_path
|
||||
from backend.utils import should_include_path
|
||||
|
||||
logger = logging.getLogger("obsigate.attachment_indexer")
|
||||
|
||||
@ -67,7 +67,7 @@ def _scan_vault_attachments(vault_name: str, vault_path: str, vault_cfg: dict =
|
||||
for fpath in vault_root.rglob("*"):
|
||||
# Check if path should be included based on hidden files configuration
|
||||
rel_parts = fpath.relative_to(vault_root).parts
|
||||
if not _should_include_path(rel_parts, vault_cfg):
|
||||
if not should_include_path(rel_parts, vault_cfg):
|
||||
continue
|
||||
|
||||
# Only process files
|
||||
|
||||
@ -9,7 +9,7 @@ from typing import Dict, List, Optional, Any
|
||||
|
||||
import frontmatter
|
||||
|
||||
from backend.attachment_indexer import build_attachment_index
|
||||
from backend.utils import should_include_path
|
||||
|
||||
logger = logging.getLogger("obsigate.indexer")
|
||||
|
||||
@ -122,38 +122,6 @@ def load_vault_config() -> Dict[str, Dict[str, Any]]:
|
||||
return vaults
|
||||
|
||||
|
||||
def _should_include_path(rel_parts: tuple, vault_config: Dict[str, Any]) -> bool:
|
||||
"""Check if a path should be included based on hidden files configuration.
|
||||
|
||||
Args:
|
||||
rel_parts: Tuple of path parts relative to vault root
|
||||
vault_config: Vault configuration dict with includeHidden and hiddenWhitelist
|
||||
|
||||
Returns:
|
||||
True if the path should be included, False otherwise
|
||||
"""
|
||||
include_hidden = vault_config.get("includeHidden", False)
|
||||
hidden_whitelist = vault_config.get("hiddenWhitelist", [])
|
||||
|
||||
# Check if any part of the path starts with a dot (hidden)
|
||||
hidden_parts = [part for part in rel_parts if part.startswith(".")]
|
||||
|
||||
if not hidden_parts:
|
||||
# No hidden parts, always include
|
||||
return True
|
||||
|
||||
if include_hidden:
|
||||
# Include all hidden files/folders
|
||||
return True
|
||||
|
||||
# Check if any hidden part is in the whitelist
|
||||
for hidden_part in hidden_parts:
|
||||
if hidden_part in hidden_whitelist:
|
||||
return True
|
||||
|
||||
# Not in whitelist and includeHidden is False
|
||||
return False
|
||||
|
||||
|
||||
# Regex for extracting inline #tags from markdown body (excludes code blocks)
|
||||
_INLINE_TAG_RE = re.compile(r'(?:^|\s)#([a-zA-Z][a-zA-Z0-9_/-]{1,50})', re.MULTILINE)
|
||||
@ -276,7 +244,7 @@ def _scan_vault(vault_name: str, vault_path: str, vault_cfg: Optional[Dict[str,
|
||||
for fpath in vault_root.rglob("*"):
|
||||
# Check if path should be included based on hidden files configuration
|
||||
rel_parts = fpath.relative_to(vault_root).parts
|
||||
if not _should_include_path(rel_parts, vault_cfg):
|
||||
if not should_include_path(rel_parts, vault_cfg):
|
||||
continue
|
||||
|
||||
rel_path_str = str(fpath.relative_to(vault_root)).replace("\\", "/")
|
||||
@ -423,6 +391,7 @@ async def build_index(progress_callback=None) -> None:
|
||||
await asyncio.gather(*tasks)
|
||||
|
||||
# Build attachment index
|
||||
from backend.attachment_indexer import build_attachment_index
|
||||
await build_attachment_index(vault_config)
|
||||
|
||||
total_files = sum(len(v["files"]) for v in index.values())
|
||||
|
||||
35
backend/utils.py
Normal file
35
backend/utils.py
Normal file
@ -0,0 +1,35 @@
|
||||
"""Utility functions shared across backend modules."""
|
||||
from typing import Dict, Any, Tuple
|
||||
|
||||
|
||||
def should_include_path(rel_parts: Tuple[str, ...], vault_config: Dict[str, Any]) -> bool:
|
||||
"""Check if a path should be included based on hidden files configuration.
|
||||
|
||||
Args:
|
||||
rel_parts: Tuple of path parts relative to vault root
|
||||
vault_config: Vault configuration dict with includeHidden and hiddenWhitelist
|
||||
|
||||
Returns:
|
||||
True if the path should be included, False otherwise
|
||||
"""
|
||||
include_hidden = vault_config.get("includeHidden", False)
|
||||
hidden_whitelist = vault_config.get("hiddenWhitelist", [])
|
||||
|
||||
# Check if any part of the path starts with a dot (hidden)
|
||||
hidden_parts = [part for part in rel_parts if part.startswith(".")]
|
||||
|
||||
if not hidden_parts:
|
||||
# No hidden parts, always include
|
||||
return True
|
||||
|
||||
if include_hidden:
|
||||
# Include all hidden files/folders
|
||||
return True
|
||||
|
||||
# Check if any hidden part is in the whitelist
|
||||
for hidden_part in hidden_parts:
|
||||
if hidden_part in hidden_whitelist:
|
||||
return True
|
||||
|
||||
# Not in whitelist and includeHidden is False
|
||||
return False
|
||||
Loading…
x
Reference in New Issue
Block a user