Skip to content

Commit

Permalink
Merge pull request #168 from ufal/add-caching
Browse files Browse the repository at this point in the history
Fix output management
  • Loading branch information
kasnerz authored Dec 9, 2024
2 parents 794e564 + d44d43d commit 9ca7b44
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion factgenie/static/js/manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function deleteOutput(dataset, split, setup_id) {
alert(response.error);
} else {
// reload
window.location.hash = "#local";
window.location.hash = "#outputs";
location.reload();
}
}
Expand Down
2 changes: 1 addition & 1 deletion factgenie/templates/pages/manage.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ <h3><img src="{{ host_prefix }}/static/img/manage.png" class="heading-img-inline
class="btn btn-outline-secondary" data-bs-toggle="tooltip" title="Export model outputs">
<i class="fa fa-download"></i>
</a>
<a onclick="deleteOutput('{{ dataset }}', '{{ split }}', '{{ setup_id }}')"
<a onclick="deleteOutput('{{ record.dataset }}', '{{ record.split }}', '{{ record.setup_id }}')"
class="btn btn-outline-danger" data-bs-toggle="tooltip" title="Delete the output">
<i class="fa fa-trash"></i>
</a>
Expand Down
12 changes: 10 additions & 2 deletions factgenie/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ def load_outputs_from_file(file_path, cols):

# drop any keys that are not in the key set
j = {k: v for k, v in j.items() if k in cols}
j["jsonl_file"] = file_path
outputs.append(j)
except Exception as e:
logger.error(
Expand All @@ -347,6 +348,13 @@ def load_outputs_from_file(file_path, cols):
return outputs


def remove_outputs(app, file_path):
"""Remove outputs from the output index for a specific file"""
if app.db["output_index"] is not None:
# Filter out outputs from the specified file
app.db["output_index"] = app.db["output_index"][app.db["output_index"]["jsonl_file"] != file_path]


def get_output_index(app, force_reload=True):
if hasattr(app, "db") and app.db["output_index"] is not None and not force_reload:
return app.db["output_index"]
Expand All @@ -362,14 +370,14 @@ def get_output_index(app, force_reload=True):
# Handle modified files
for file_path, mod_time in current_outs.items():
if file_path not in cached_outs or cached_outs[file_path] < mod_time:
remove_outputs(app, file_path)
new_outputs.extend(load_outputs_from_file(file_path, cols))

# Handle deleted files
for file_path in set(cached_outs.keys()) - set(current_outs.keys()):
# Remove outputs for deleted files from the index
if app.db["output_index"] is not None:
file_mask = app.db["output_index"]["file_path"] == file_path
app.db["output_index"] = app.db["output_index"][~file_mask]
remove_outputs(app, file_path)

# Update the cache
app.db["output_index_cache"] = current_outs
Expand Down

0 comments on commit 9ca7b44

Please sign in to comment.