Skip to content

Commit

Permalink
Cache data for ortho table
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthieuBarba committed May 3, 2024
1 parent 55f3821 commit 2300aaa
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 6 deletions.
5 changes: 5 additions & 0 deletions css/summary.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ table a:hover {
margin-right: auto;
max-width: 500px;
}

#clear_cache {
margin-left: auto;
margin-right: auto;
}
51 changes: 45 additions & 6 deletions js/summary.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
storage = $.localStorage;

// Write the genomes table
function genomes_table(data) {
if (data['outcome'] && data['outcome'] == false) {
Expand Down Expand Up @@ -174,22 +176,54 @@ function links(can_search) {

}

function get_cached_data( cname ) {
cached_data = storage.get( cname );
console.log("CACHED = ");
}

function create_table(pars) {
// Get all the genomes names for the menu
pars.type = 'genomes';
$.getJSON( urls.get_data, pars, function(data) {
genomes_table(data);

// Also get all the genomes orthologs numbers
pars.type = 'genomes_ortho';
loading_on();
console.log(pars);
console.log(urls.get_data);
$.getJSON( urls.get_data, pars, function(orthos) {
loading_off();

// Get from cache
cname = "summary_" + get_par("version") + "_numorthos";
if ( storage.isSet( cname )) {
orthos = storage.get( cname );
data.num_ortho = orthos.num_ortho;
console.log(data);
links_table(data);
});
loading_off();
} else {
console.log(pars);
console.log(urls.get_data);
$.getJSON( urls.get_data, pars, function(orthos) {
loading_off();
if (orthos['outcome'] == true) {
console.log("Can't get ortho data");
} else {
try {
storage.set( cname, orthos );
} catch (e) {
console.log("Data cache is full: purging.");
storage.removeAll();
try {
storage.set( cname, orthos );
} catch(e) {
console.log("Can't cache");
}
}
console.log("Data stored in " + cname);
data.num_ortho = orthos.num_ortho;
console.log(data);
links_table(data);
}
});
}
});
}

Expand All @@ -204,5 +238,10 @@ $(function() {
} else {
$("#message").text("No database name provided.");
}
$('#clear_cache').click(function(event) {
event.preventDefault();
console.log("Clear cache...");
storage.removeAll();
});
});

2 changes: 2 additions & 0 deletions summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<link rel="stylesheet" type="text/css" href="css/common.css">
<link rel="stylesheet" type="text/css" href="css/summary.css">
<script type="text/javascript" src="js/jquery/jquery-1.12.min.js"></script>
<script type="text/javascript" src="js/jquery/jquery.storageapi.min.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="js/summary.js"></script>

Expand Down Expand Up @@ -41,6 +42,7 @@
<li><img src="css/ranking_32.png" alt="Show rankings icon"> = List of the genomic islands</li>
<li>"synt: xx%" indicates the level of synteny between two genomes (number of orthologs in synteny blocks / number of orthologs between two genomes).</li>
</ul>
<button id="clear_cache" type="button">Clear cache</button>
</div>
</div>
</div>
Expand Down

0 comments on commit 2300aaa

Please sign in to comment.