diff --git a/backup_service.py b/backup_service.py index 6bab580..4322ae3 100644 --- a/backup_service.py +++ b/backup_service.py @@ -1,14 +1,13 @@ import os import re -import git import shutil -import requests import zipfile import tarfile import logging from datetime import datetime, timedelta from pathlib import Path -from github import Github +# PyGithub and requests are imported inside the methods that use them, so the +# idle web process doesn't keep these heavy modules (~30 MB) in memory. from models import db, BackupJob, RELEASE_MODES from urllib.parse import urlparse @@ -326,6 +325,7 @@ def _safe_filename(self, name): def _download_file(self, url, destination, headers): """Stream a file from the GitHub API to disk""" + import requests with requests.get(url, headers=headers, stream=True, timeout=(30, 300), allow_redirects=True) as response: response.raise_for_status() with open(destination, 'wb') as f: @@ -348,6 +348,7 @@ def _download_releases(self, repository, releases_dir): owner, repo_name = owner_repo token = repository.github_token.strip() if repository.github_token else '' + from github import Github g = Github(token) if token else Github() gh_repo = g.get_repo(f"{owner}/{repo_name}") @@ -520,6 +521,7 @@ def verify_github_access(self, repo_url, github_token=None): if repo_name.endswith('.git'): repo_name = repo_name[:-4] + from github import Github if github_token: g = Github(github_token) else: diff --git a/requirements.txt b/requirements.txt index df4d5e2..61f7d36 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,6 @@ werkzeug==3.1.8 bcrypt==5.0.0 APScheduler==3.11.3 PyGithub==2.10.0 -gitpython==3.1.62 python-dotenv==1.2.3 requests==2.34.2 sqlalchemy==2.0.54