Skip to content

Commit

Permalink
Fix #426: Added "Clear cache" button to Analyze view.
Browse files Browse the repository at this point in the history
This forces recomputing the materialized view.
  • Loading branch information
glebkuznetsov committed Jul 22, 2015
1 parent 67fd589 commit 634db63
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
18 changes: 18 additions & 0 deletions genome_designer/main/static/js/variants_table_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ gd.VariantsTableComponent = Backbone.View.extend({
$('#gd-filter-field-select-btn').click(
_.bind(this.handleShowFieldSelect, this));

// Decorate force refresh materialized view.
$('#gd-filter-force-refresh-btn').click(
_.bind(this.handleForceRefreshMaterializedView, this));

// Manually handle error alert close.
$('#gd-snp-filter-error-close-btn').click(
_.bind(this.handleErrorAlertClose, this));
Expand Down Expand Up @@ -232,6 +236,18 @@ gd.VariantsTableComponent = Backbone.View.extend({
})
},

/** Forces refereshing the materialized view. */
handleForceRefreshMaterializedView: function() {
var requestData = {
'refGenomeUid': this.model.get('refGenomeUid'),
};
$.post('/_/variants/invalidate_materialized_view', requestData,
_.bind(function() {
this.renderDatatable();
}, this));

},

/**
* Hides the alert box.
*
Expand Down Expand Up @@ -362,6 +378,8 @@ gd.VariantsTableComponent = Backbone.View.extend({
handleRefreshMaterializedView: function(onSuccess) {
this.setUIStartLoadingState();

$('#gd-datatable-hook').empty();

// Show special message indicating this initial load might be a bit long.
$('#gd-datatable-hook').append(
'<div id="gd-refresh-materialized-view-msg" ' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
Fields...
</button>
</div>
<div class="btn-group">
<button id="gd-filter-force-refresh-btn" class="btn btn-default gd-btn-with-margins"
title="Views are cached for speed but may become stale. Click to force refresh.">
Clear Cache
</button>
</div>
</div>
</div>
</div>
Expand Down
14 changes: 14 additions & 0 deletions genome_designer/main/xhr_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,20 @@ def is_materialized_view_valid(request):
return HttpResponse(response_data, content_type='application/json')


@login_required
@require_POST
def invalidate_materialized_view(request):
"""Checks whether the materialized view is valid for this ReferenceGenome.
"""
ref_genome_uid = request.POST.get('refGenomeUid')
reference_genome = get_object_or_404(ReferenceGenome,
project__owner=request.user.get_profile(),
uid=ref_genome_uid)
reference_genome.invalidate_materialized_view()
response_data = json.dumps({})
return HttpResponse(response_data, content_type='application/json')


@login_required
@require_GET
def get_ref_genomes(request):
Expand Down
2 changes: 2 additions & 0 deletions genome_designer/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@
'main.xhr_handlers.export_variants_as_csv'),
url(r'^_/variants/is_materialized_view_valid$',
'main.xhr_handlers.is_materialized_view_valid'),
url(r'^_/variants/invalidate_materialized_view$',
'main.xhr_handlers.invalidate_materialized_view'),
url(r'^_/variants/delete$',
'main.xhr_handlers.variant_sets_delete'),
url(r'^_/variants/save_filter$',
Expand Down

0 comments on commit 634db63

Please sign in to comment.