Skip to content

Commit

Permalink
Reduce calling scp, cache result
Browse files Browse the repository at this point in the history
  • Loading branch information
DJ3CE committed Mar 25, 2024
1 parent 40dc26c commit 15e2e10
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 25 deletions.
2 changes: 1 addition & 1 deletion application/controllers/Lookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function scp() {

foreach ($arCalls as $strCall)
{
echo " " . $strCall . " ";
echo $strCall . " ";
}

}
Expand Down
45 changes: 33 additions & 12 deletions assets/js/sections/contesting.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ $(document).ready(async function () {
setRst($("#mode").val());
});

var scp_data = {
request: "",
status: -1 , // -1 - never req, 0 - req in progress, 1 - request done
data: [],
};

// Resets the logging form and deletes session from database
function reset_contest_session() {
$('#name').val("");
Expand Down Expand Up @@ -208,20 +214,35 @@ $('#start_date').change(function () {

// On Key up check and suggest callsigns
$("#callsign").keyup(function () {
var call = $(this).val();
var call = $(this).val().toUpperCase();
if (call.length >= 3) {

$.ajax({
url: 'lookup/scp',
method: 'POST',
data: {
callsign: $(this).val().toUpperCase()
},
success: function (result) {
$('.callsign-suggestions').text(result);
highlight(call.toUpperCase());
}
});
if (scp_data.status < 0 || scp_data.request != call.substr(0, scp_data.request.length)) {
scp_data.status = 0;
scp_data.request = call;
scp_data.data = [];
$.ajax({
url: 'lookup/scp',
method: 'POST',
data: {
callsign: call
},
success: function (result) {
scp_data.status = 1;
scp_data.data = result.split(" ");

var call = $("#callsign").val().toUpperCase(); // Might have changed while running the query...
$('.callsign-suggestions').text(scp_data.data.filter((el) => el.startsWith(call)).join(' '));
highlight(call);
}
});

} else {
// Filter the already obtained list:
$('.callsign-suggestions').text(scp_data.data.filter((el) => el.startsWith(call)).join(' '));
highlight(call);

}
// moved to blur
// checkIfWorkedBefore();
var qTable = $('.qsotable').DataTable();
Expand Down
42 changes: 30 additions & 12 deletions assets/js/sections/qso.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
var lastCallsignUpdated=""
var scp_data = {
request: "",
status: -1 , // -1 - never req, 0 - req in progress, 1 - request done
data: [],
};

$( document ).ready(function() {
setTimeout(function() {
Expand Down Expand Up @@ -1019,18 +1024,31 @@ $("#callsign").on("keypress", function(e) {
// On Key up check and suggest callsigns
$("#callsign").keyup(function() {
if ($(this).val().length >= 3) {
$('.callsign-suggest').show();
$callsign = $(this).val().replace('Ø', '0');
$.ajax({
url: 'lookup/scp',
method: 'POST',
data: {
callsign: $callsign.toUpperCase()
},
success: function(result) {
$('.callsign-suggestions').text(result);
}
});
$callsign = $(this).val().replace('Ø', '0').toUpperCase();

if (scp_data.status < 0 || scp_data.request != $callsign.substr(0, scp_data.request.length)) {
scp_data.status = 0;
scp_data.request = $callsign;
scp_data.data = [];
$.ajax({
url: 'lookup/scp',
method: 'POST',
data: {
callsign: $callsign
},
success: function(result) {
scp_data.status = 1;
scp_data.data = result.split(" ");

var call = $("#callsign").val().replace('Ø', '0').toUpperCase();
$('.callsign-suggestions').text(scp_data.data.filter((el) => el.startsWith(call)).join(' '));
$('.callsign-suggest').show();
}
});
} else {
$('.callsign-suggestions').text(scp_data.data.filter((el) => el.startsWith($callsign)).join(' '));
$('.callsign-suggest').show();
}
}
});

Expand Down

0 comments on commit 15e2e10

Please sign in to comment.