Skip to content

Commit 6499fe1

Browse files
Nakshatra SharmaNakshatra Sharma
authored andcommitted
Remove inline comments and extra whitespace
1 parent 5582701 commit 6499fe1

File tree

4 files changed

+0
-38
lines changed

4 files changed

+0
-38
lines changed

backend/app/config/settings.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,4 @@
2020
DATABASE_PATH = "app/database/PictoPy.db"
2121
THUMBNAIL_IMAGES_PATH = "./images/thumbnails"
2222
IMAGES_PATH = "./images"
23-
24-
# Backend API URL (used by watcher to call backend endpoints)
2523
BACKEND_URL = "http://localhost:52123"

backend/app/utils/API.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
logger = logging.getLogger(__name__)
44

5-
65
def API_util_restart_sync_microservice_watcher():
76
"""
87
Restart the folder watcher (now integrated into the backend).
@@ -11,18 +10,14 @@ def API_util_restart_sync_microservice_watcher():
1110
bool: True if restart was successful, False otherwise
1211
"""
1312
try:
14-
# Import here to avoid circular dependencies
1513
from app.utils.watcher import watcher_util_restart_folder_watcher
16-
1714
success = watcher_util_restart_folder_watcher()
18-
1915
if success:
2016
logger.info("Successfully restarted folder watcher")
2117
return True
2218
else:
2319
logger.warning("Failed to restart folder watcher")
2420
return False
25-
2621
except Exception as e:
2722
logger.error(f"Unexpected error restarting folder watcher: {e}")
2823
return False

backend/app/utils/watcher.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from app.config.settings import *
1010
from app.logging.setup_logging import get_logger
1111

12-
# Configure third-party loggers
1312
logging.getLogger("httpx").setLevel(logging.WARNING)
1413
logging.getLogger("httpcore").setLevel(logging.WARNING)
1514
logging.getLogger("watchfiles").setLevel(logging.WARNING) # Silence watchfiles logger
@@ -21,7 +20,6 @@
2120

2221
FolderIdPath = Tuple[str, str]
2322

24-
# Global variables to track watcher state
2523
watcher_thread: Optional[threading.Thread] = None
2624
stop_event = threading.Event()
2725
watched_folders: List[FolderIdPath] = []
@@ -38,10 +36,8 @@ def watcher_util_get_folder_id_if_watched(file_path: str) -> Optional[str]:
3836
Returns:
3937
Folder ID if the path is a watched folder, None otherwise
4038
"""
41-
# Normalize the file path
4239
normalized_path = os.path.abspath(file_path)
4340

44-
# Check if this path matches any of our watched folders
4541
for folder_id, folder_path in watched_folders:
4642
if os.path.abspath(folder_path) == normalized_path:
4743
return folder_id
@@ -60,28 +56,23 @@ def watcher_util_handle_file_changes(changes: set) -> None:
6056

6157
affected_folders = {} # folder_path -> folder_id mapping
6258

63-
# First pass - count changes and identify affected folders
6459
for change, file_path in changes:
65-
# Process deletions
6660
if change == Change.deleted:
6761
deleted_folder_id = watcher_util_get_folder_id_if_watched(file_path)
6862
if deleted_folder_id:
6963
deleted_folder_ids.append(deleted_folder_id)
7064
continue
7165

72-
# Find affected folder
7366
closest_folder = watcher_util_find_closest_parent_folder(
7467
file_path, watched_folders
7568
)
7669
if closest_folder:
7770
folder_id, folder_path = closest_folder
7871
affected_folders[folder_path] = folder_id
7972

80-
# Process affected folders
8173
for folder_path, folder_id in affected_folders.items():
8274
watcher_util_call_sync_folder_api(folder_id, folder_path)
8375

84-
# Handle deleted folders
8576
if deleted_folder_ids:
8677
logger.info(f"Processing {len(deleted_folder_ids)} deleted folders")
8778
watcher_util_call_delete_folders_api(deleted_folder_ids)
@@ -101,21 +92,16 @@ def watcher_util_find_closest_parent_folder(
10192
Returns:
10293
Tuple of (folder_id, folder_path) if found, None otherwise
10394
"""
104-
# Normalize the file path
10595
file_path = os.path.abspath(file_path)
10696

10797
best_match = None
10898
longest_match_length = 0
10999

110100
for folder_id, folder_path in watched_folders:
111-
# Normalize the folder path
112101
folder_path = os.path.abspath(folder_path)
113102

114-
# Check if this folder is a parent of the file
115103
if file_path.startswith(folder_path):
116-
# Ensure it's a proper parent (not just a prefix)
117104
if file_path == folder_path or file_path[len(folder_path)] == os.sep:
118-
# Choose the longest matching path (closest parent)
119105
if len(folder_path) > longest_match_length:
120106
longest_match_length = len(folder_path)
121107
best_match = (folder_id, folder_path)
@@ -132,7 +118,6 @@ def watcher_util_call_sync_folder_api(folder_id: str, folder_path: str) -> None:
132118
folder_path: Path of the folder to sync
133119
"""
134120
try:
135-
# Import settings here to avoid circular dependencies
136121
from app.config.settings import BACKEND_URL
137122
url = f"{BACKEND_URL}/folders/sync-folder"
138123
payload = {"folder_path": folder_path, "folder_id": folder_id}
@@ -163,7 +148,6 @@ def watcher_util_call_delete_folders_api(folder_ids: List[str]) -> None:
163148
folder_ids: List of folder IDs to delete
164149
"""
165150
try:
166-
# Import settings here to avoid circular dependencies
167151
from app.config.settings import BACKEND_URL
168152
url = f"{BACKEND_URL}/folders/delete-folders"
169153
payload = {"folder_ids": folder_ids}
@@ -202,13 +186,11 @@ def watcher_util_watcher_worker(folder_paths: List[str]) -> None:
202186
logger.info("Stop event detected in watcher loop")
203187
break
204188

205-
# Log changes at debug level before processing
206189
if logger.isEnabledFor(10): # DEBUG level is 10
207190
from app.utils.watcher_helpers import format_debug_changes
208191

209192
logger.debug("Detailed changes:\n %s", format_debug_changes(changes))
210193

211-
# Process changes
212194
watcher_util_handle_file_changes(changes)
213195
except Exception as e:
214196
logger.error(f"Error in watcher worker: {e}")
@@ -259,11 +241,8 @@ def watcher_util_start_folder_watcher() -> bool:
259241
logger.debug("Debug logging is enabled")
260242

261243
try:
262-
# Get all folder details from database
263-
# db_get_all_folder_details returns: List[Tuple[folder_id, folder_path, parent_folder_id, last_modified_time, AI_Tagging, taggingCompleted]]
264244
all_folder_details = db_get_all_folder_details()
265245

266-
# Extract just folder_id and folder_path (first two elements of tuple)
267246
folders = [(folder_id, folder_path) for folder_id, folder_path, *_ in all_folder_details]
268247

269248
if not folders:
@@ -272,7 +251,6 @@ def watcher_util_start_folder_watcher() -> bool:
272251

273252
logger.info(f"Found {len(folders)} folders in database")
274253

275-
# Simple synchronous file system checks
276254
existing_folders = watcher_util_get_existing_folders(folders)
277255
if not existing_folders:
278256
logger.info("No existing folders to watch")
@@ -289,7 +267,6 @@ def watcher_util_start_folder_watcher() -> bool:
289267
for folder_id, folder_path in existing_folders:
290268
logger.info(f" - {folder_path} (ID: {folder_id})")
291269

292-
# Reset stop event and start background thread
293270
stop_event.clear()
294271
watcher_thread = threading.Thread(
295272
target=watcher_util_watcher_worker,
@@ -317,10 +294,8 @@ def watcher_util_stop_folder_watcher() -> None:
317294
try:
318295
logger.info("Stopping folder watcher...")
319296

320-
# Signal the watcher to stop
321297
stop_event.set()
322298

323-
# Wait for thread to finish
324299
watcher_thread.join(timeout=5.0)
325300

326301
if watcher_thread.is_alive():
@@ -332,7 +307,6 @@ def watcher_util_stop_folder_watcher() -> None:
332307
logger.error(f"Error stopping watcher: {e}")
333308
finally:
334309
watcher_thread = None
335-
# Clear state
336310
watched_folders = []
337311
folder_id_map = {}
338312

backend/main.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,17 @@ async def lifespan(app: FastAPI):
5252
db_create_albums_table()
5353
db_create_album_images_table()
5454
db_create_metadata_table()
55-
# Create ProcessPoolExecutor and attach it to app.state
5655
app.state.executor = ProcessPoolExecutor(max_workers=1)
57-
58-
# Start folder watcher
5956
from app.utils.watcher import watcher_util_start_folder_watcher, watcher_util_stop_folder_watcher
6057
watcher_started = watcher_util_start_folder_watcher()
6158
if watcher_started:
6259
logger.info("Folder watcher started successfully")
6360
else:
6461
logger.warning("Folder watcher did not start (no folders to watch or already running)")
65-
6662
try:
6763
yield
6864
finally:
6965
app.state.executor.shutdown(wait=True)
70-
# Stop folder watcher
7166
if watcher_started:
7267
watcher_util_stop_folder_watcher()
7368
logger.info("Folder watcher stopped")

0 commit comments

Comments
 (0)