Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce calling scp, cache result #3025

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = {
DJ3CE marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be let, i will net let it go.

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();
DJ3CE marked this conversation as resolved.
Show resolved Hide resolved
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)) {
DJ3CE marked this conversation as resolved.
Show resolved Hide resolved
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...
DJ3CE marked this conversation as resolved.
Show resolved Hide resolved
$('.callsign-suggestions').text(scp_data.data.filter((el) => el.startsWith(call)).join(' '));
DJ3CE marked this conversation as resolved.
Show resolved Hide resolved
highlight(call);
}
});

} else {
// Filter the already obtained list:
$('.callsign-suggestions').text(scp_data.data.filter((el) => el.startsWith(call)).join(' '));
DJ3CE marked this conversation as resolved.
Show resolved Hide resolved
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 = {
DJ3CE marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another let

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();
DJ3CE marked this conversation as resolved.
Show resolved Hide resolved

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();
}
DJ3CE marked this conversation as resolved.
Show resolved Hide resolved
}
});

Expand Down