Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 6 additions & 26 deletions dbsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,29 +520,9 @@ def _print_mergin_changes(
logging.debug(" removed: " + item["path"])


# Dictionary used by _get_mergin_project() function below.
# key = path to a local dir with Mergin project, value = cached MerginProject object
cached_mergin_project_objects = {}


def _get_mergin_project(work_path) -> MerginProject:
"""
Returns a cached MerginProject object or creates one if it does not exist yet.
This is to avoid creating many of these objects (e.g. every pull/push) because it does
initialization of geodiff as well, so things should be 1. a bit faster, and 2. safer.
(Safer because we are having a cycle of refs between GeoDiff and MerginProject objects
related to logging - and untangling those would need some extra calls when we are done
with MerginProject. But since we use the object all the time, it's better to cache it anyway.)
"""
if work_path not in cached_mergin_project_objects:
cached_mergin_project_objects[work_path] = MerginProject(work_path)
cached_mergin_project_objects[work_path]._read_metadata()
return cached_mergin_project_objects[work_path]


def _get_project_version(work_path) -> str:
"""Returns the current version of the project"""
mp = _get_mergin_project(work_path)
mp = MerginProject(work_path)
return mp.version()


Expand Down Expand Up @@ -740,7 +720,7 @@ def pull(conn_cfg, mc):
_check_has_working_dir(work_dir)
_check_has_sync_file(gpkg_full_path)

mp = _get_mergin_project(work_dir)
mp = MerginProject(work_dir)
mp.set_tables_to_skip(ignored_tables)
if mp.geodiff is None:
raise DbSyncError("Mergin Maps client installation problem: geodiff not available")
Expand Down Expand Up @@ -889,7 +869,7 @@ def status(conn_cfg, mc):
_check_has_sync_file(gpkg_full_path)

# get basic information
mp = _get_mergin_project(work_dir)
mp = MerginProject(work_dir)
mp.set_tables_to_skip(ignored_tables)
if mp.geodiff is None:
raise DbSyncError("Mergin Maps client installation problem: geodiff not available")
Expand Down Expand Up @@ -994,7 +974,7 @@ def push(conn_cfg, mc):
_check_has_working_dir(work_dir)
_check_has_sync_file(gpkg_full_path)

mp = _get_mergin_project(work_dir)
mp = MerginProject(work_dir)
mp.set_tables_to_skip(ignored_tables)
if mp.geodiff is None:
raise DbSyncError("Mergin Maps client installation problem: geodiff not available")
Expand Down Expand Up @@ -1161,7 +1141,7 @@ def init(
None,
)
db_project_id = uuid.UUID(db_project_id_str) if db_project_id_str else None
mp = _get_mergin_project(work_dir)
mp = MerginProject(work_dir)
local_project_id = _get_project_id(mp)
if (db_project_id and local_project_id) and (db_project_id != local_project_id):
raise DbSyncError("Database project ID doesn't match local project ID. " f"{FORCE_INIT_MESSAGE}")
Expand All @@ -1186,7 +1166,7 @@ def init(
# make sure we have working directory now
_check_has_working_dir(work_dir)
local_version = _get_project_version(work_dir)
mp = _get_mergin_project(work_dir)
mp = MerginProject(work_dir)
# Make sure that local project ID (if available) is the same as on the server
_validate_local_project_id(mp, mc)

Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mergin-client==0.9.0
mergin-client==0.12.0
dynaconf>=3.1
psycopg2>=2.9
psycopg2>=2.9