Skip to content

Commit

Permalink
Optimize update command
Browse files Browse the repository at this point in the history
  • Loading branch information
douglaslassance committed Feb 7, 2025
1 parent 87cbbad commit 7057d3e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
10 changes: 5 additions & 5 deletions gitalong/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,6 @@ async def update_files_permissions(filenames: List[str]):
repository = Repository.from_filename(os.path.dirname(filename))
if not repository:
continue
if not repository.config.get("modify_permissions"):
continue
spread = last_commit.commit_spread
if not spread:
continue
Expand Down Expand Up @@ -414,9 +412,11 @@ async def update_tracked_commits(
repository, claims=claims
)
absolute_filenames = []
for filename in repository.files:
absolute_filenames.append(repository.get_absolute_path(filename))
await repository.batch.update_files_permissions(absolute_filenames)
if repository.config.get("modify_permissions"):
print("Updating permissions")
for filename in repository.files:
absolute_filenames.append(repository.get_absolute_path(filename))
await repository.batch.update_files_permissions(absolute_filenames)


async def claim_files(
Expand Down
10 changes: 10 additions & 0 deletions gitalong/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,13 @@ def get_filenames_from_move_string(move_string: str) -> tuple:
rights.append(splits[-1])
pair = {move_string.format(*lefts), move_string.format(*rights)}
return tuple(sorted(pair))


def touch_file(filename: str) -> None:
"""
Args:
filename (str): The file to touch.
"""
with open(filename, "a", encoding="utf-8"):
pass
os.utime(filename)
11 changes: 8 additions & 3 deletions gitalong/stores/jsonbin_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import requests

from ..exceptions import StoreNotReachable, RepositoryInvalidConfig
from ..functions import modified_within
from ..functions import modified_within, touch_file
from ..store import Store
from ..commit import Commit

Expand All @@ -26,18 +26,23 @@ def _local_json_path(self) -> str:
self._managed_repository.working_dir, ".gitalong", "commits.json"
)

@property
def _pull_timestamp_path(self) -> str:
return os.path.join(self._managed_repository.working_dir, ".gitalong", ".pull")

@property
def commits(self) -> typing.List[Commit]:
headers = {}
for key, value in self._headers.items():
headers[key] = os.path.expandvars(value)
pull_threshold = self._managed_repository.config.get("pull_threshold", 60)
serializable_commits = []
if modified_within(self._local_json_path, pull_threshold):
serializable_commits = self._read_local_json()
if modified_within(self._pull_timestamp_path, pull_threshold):
return self._serializeables_to_commits(self._read_local_json())
response = requests.get(self._url, headers=headers, timeout=self._timeout)
if response.status_code != 200:
raise StoreNotReachable(response.status_code, response.text)
touch_file(self._pull_timestamp_path)
serializable_commits = response.json()["record"]
self._write_local_json(serializable_commits)
return self._serializeables_to_commits(serializable_commits)
Expand Down

0 comments on commit 7057d3e

Please sign in to comment.