Bläddra i källkod

batch load jobs performance tuning

master
patrick 6 år sedan
förälder
incheckning
d3cae6fbdd
3 ändrade filer med 39 tillägg och 22 borttagningar
  1. +10
    -4
      Xero.php
  2. +26
    -17
      js/bts_timesheet.js
  3. +3
    -1
      ts.php

+ 10
- 4
Xero.php Visa fil

// //
//sync users to wordpress system //sync users to wordpress system
//does not work for too many users or employees //does not work for too many users or employees
public function sync_users($mininterval){
public function sync_users($mininterval, $employeeonly, $clientsonly){
$this->usage(); $this->usage();
$this->minimum_sync_interval_in_seconds = $mininterval; $this->minimum_sync_interval_in_seconds = $mininterval;
$msg="Sync users with minimum interval set to $mininterval \n"; $msg="Sync users with minimum interval set to $mininterval \n";
$this->logConsole($msg); $this->logConsole($msg);
try{ try{
$this->sync_clients();
$this->sync_employees();
if ($clientsonly){
$this->sync_clients();
}else if ($employeeonly){
$this->sync_employees();
}else{
$this->sync_clients();
$this->sync_employees();
}
}catch(RateLimitExceededException $e){ }catch(RateLimitExceededException $e){
$msg= "Xero API rate limit exceeded, please try again later, existing sync within 600 seconds will by passed automatically\n"; $msg= "Xero API rate limit exceeded, please try again later, existing sync within 600 seconds will by passed automatically\n";
$this->logConsole($msg); $this->logConsole($msg);
$msg .= "wp sync_users --mininterval=6000 \n"; $msg .= "wp sync_users --mininterval=6000 \n";
$msg .= "6000 means those users synced within 6000 seconds will be bypassed \n"; $msg .= "6000 means those users synced within 6000 seconds will be bypassed \n";
$msg .= "to sync everything \n"; $msg .= "to sync everything \n";
$msg .= "wp sync_users --mininterval=0 \n";
$msg .= "wp sync_users --mininterval=0 [--clientsonly] [--employeeonly]\n";
$msg .= "but it may hit XERO rate limit, 60call/sec, 5000/day \n"; $msg .= "but it may hit XERO rate limit, 60call/sec, 5000/day \n";
$msg .= "---------------------------------------------\n"; $msg .= "---------------------------------------------\n";
$this->logConsole($msg); $this->logConsole($msg);

+ 26
- 17
js/bts_timesheet.js Visa fil

return; return;
var table = $(this).closest('div.divTable'); var table = $(this).closest('div.divTable');
var job = table.data().job; var job = table.data().job;
clone_data_create_new_job(job.get_record_from_ui());
var newj = clone_data_create_new_job(job.get_record_from_ui());
$('div.workspace').append(newj.el);
newj.el.get(0).scrollIntoView();//make sure it's visible;
newj.mark_highlight_me(1000);//for 1 second;
dtp_init(); dtp_init();
}); });
if (!confirm ('copy entire week to next week? ')) if (!confirm ('copy entire week to next week? '))
return; return;
var jobs = []; var jobs = [];
var job_els =[];
$('div.week1 >div').each(function(i,e){ $('div.week1 >div').each(function(i,e){
var date = new Date($(e).find('span.weekday').data().date); var date = new Date($(e).find('span.weekday').data().date);
var strDate = format_date(date); //yyyy-mm-dd var strDate = format_date(date); //yyyy-mm-dd
var el = $(e).closest('div.divTable'); var el = $(e).closest('div.divTable');
if (el.is(":visible")){ if (el.is(":visible")){
var j = el.data().job; var j = el.data().job;
jobs.push(j);
var newj = clone_data_create_new_job(j.get_record_from_ui(),7);//add 7 days
job_els.push(newj.el);
} }
} }
}); });
}); });
jobs.forEach(function(e){
clone_data_create_new_job(e.get_record_from_ui(),7);//add 7 days
});
dtp_init();
show_jobs(job_els);
debounced_calculate(); debounced_calculate();
}); });
} }
if (!confirm ('copy to next week')) if (!confirm ('copy to next week'))
return; return;
var jobs_el = [];
$('div.bstart input.blink_me').each(function(i,e){ $('div.bstart input.blink_me').each(function(i,e){
copy_single_day_to_next_week(e);
var r = copy_single_day_to_next_week(e);
if (r != false)
jobs_el.push(r.el);
}); });
show_jobs(jobs_el);
unblink_all_date(); unblink_all_date();
}); });
var tb = $(el).closest('div.divTable'); var tb = $(el).closest('div.divTable');
if (tb.is(':visible')){ if (tb.is(':visible')){
var j = $(tb).data().job; var j = $(tb).data().job;
clone_data_create_new_job(j.get_record_from_ui() , 7); // +7 days
var newj = clone_data_create_new_job(j.get_record_from_ui() , 7); // +7 days
return newj;
} }
dtp_init();
return false;
} }
function clone_data_create_new_job(val, num_of_shifted_days){ function clone_data_create_new_job(val, num_of_shifted_days){
data.finish = format_date_time(f); data.finish = format_date_time(f);
} }
var newj = new Job(data); var newj = new Job(data);
newj.mark_highlight_me(1000);//for 1 second;
return newj;
} }
function is_valid_date_str(val){ function is_valid_date_str(val){
if (response.status =='success'){ if (response.status =='success'){
var job_els = []; var job_els = [];
response.jobs.forEach(function(job){ response.jobs.forEach(function(job){
console.log('loading job... %o', job);
//console.log('loading job... %o', job);
var o = new Job(job); var o = new Job(job);
job_els.push(o.el); job_els.push(o.el);
}); });
show_jobs(job_els);
show_jobs(job_els, 'in-ajax=true');
//filter it if reqired //filter it if reqired
do_filter_workspace();
debounced_filter_workspace();
}else{ }else{
alert('error loading job'); alert('error loading job');
} }
} }
function show_jobs(job_els){
function show_jobs(job_els, in_ajax){
if (job_els.length >0){ if (job_els.length >0){
$('div.workspace').append(job_els); $('div.workspace').append(job_els);
job_els[0].get(0).scrollIntoView(); job_els[0].get(0).scrollIntoView();
console.log('loading ... %d jobs', job_els.length);
} }
if (typeof in_ajax =='undefined')
dtp_init();
} }
function format_date(date){ function format_date(date){
}); });
$(document).on('click','div.userlist', debounce(do_filter_workspace));
var debounced_filter_workspace = debounce(do_filter_workspace, 1000);
$(document).on('click','div.userlist', debounced_filter_workspace);
function do_filter_workspace(){ function do_filter_workspace(){
var staffs =[]; var staffs =[];

+ 3
- 1
ts.php Visa fil

public function sync_user_cli($args = array(), $assoc_args = array()){ public function sync_user_cli($args = array(), $assoc_args = array()){
$arguments = wp_parse_args( $assoc_args, array( $arguments = wp_parse_args( $assoc_args, array(
'mininterval' => 600, 'mininterval' => 600,
'employeeonly' => false,
'clientsonly' => false,
) ); ) );
$this->xero->sync_users($arguments['mininterval']);
$this->xero->sync_users($arguments['mininterval'], $arguments['employeeonly'], $arguments['clientsonly']);
return; return;
} }

Laddar…
Avbryt
Spara