Skip to content

Commit

Permalink
In file changesets details endpoint invoke full geopackage reconstruc…
Browse files Browse the repository at this point in the history
…tion if needed
  • Loading branch information
varmar05 committed Jul 21, 2023
1 parent 18e3678 commit 2cdf27c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions server/mergin/sync/public_api_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,8 @@ def get_resource_changeset(project_name, namespace, version_id, path): # noqa:
project.storage.flush_geodiff_logger() # clean geodiff logger

try:
if not os.path.exists(basefile):
version.project.storage.restore_versioned_file(path, version_id)
if not os.path.exists(json_file):
version.project.storage.geodiff.list_changes(changeset, json_file)
if not os.path.exists(schema_file):
Expand Down
20 changes: 14 additions & 6 deletions server/mergin/tests/test_project_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1848,24 +1848,32 @@ def test_file_diffs_chain(diff_project):

@pytest.mark.parametrize("version, path, expected", changeset_data)
def test_changeset_file(client, diff_project, version, path, expected):
pv = ProjectVersion.query.filter_by(
project_id=diff_project.id, name=version
).first()

url = "/v1/resource/changesets/{}/{}/{}?path={}".format(
test_workspace_name, test_project, version, path
)
resp = client.get(url)
assert resp.status_code == expected

if expected == 200 and is_versioned_file(path):
# remove gpkg file, so it is reconstructed on demand and request still works
f = pv.project.storage.file_path(os.path.join(version, path))
if os.path.exists(f):
os.remove(f)
assert client.get(url).status_code == 200

if resp.status_code == 200:
version = ProjectVersion.query.filter_by(
project_id=diff_project.id, name=version
).first()
file = next((f for f in version.files if f["path"] == path), None)
file = next((f for f in pv.files if f["path"] == path), None)
changeset = os.path.join(
version.project.storage.project_dir, file["diff"]["location"]
pv.project.storage.project_dir, file["diff"]["location"]
)
json_file = "changeset"

# create manually list changes
version.project.storage.geodiff.list_changes(changeset, json_file)
pv.project.storage.geodiff.list_changes(changeset, json_file)
list_changes = json.loads(open(json_file, "r").read())
os.remove(json_file)

Expand Down

0 comments on commit 2cdf27c

Please sign in to comment.