Parcourir la source

batch load jobs performance tuning

master
patrick il y a 6 ans
Parent
révision
d3cae6fbdd
3 fichiers modifiés avec 39 ajouts et 22 suppressions
  1. +10
    -4
      Xero.php
  2. +26
    -17
      js/bts_timesheet.js
  3. +3
    -1
      ts.php

+ 10
- 4
Xero.php Voir le fichier

@@ -72,15 +72,21 @@ class Xero {
//
//sync users to wordpress system
//does not work for too many users or employees
public function sync_users($mininterval){
public function sync_users($mininterval, $employeeonly, $clientsonly){
$this->usage();
$this->minimum_sync_interval_in_seconds = $mininterval;
$msg="Sync users with minimum interval set to $mininterval \n";
$this->logConsole($msg);
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){
$msg= "Xero API rate limit exceeded, please try again later, existing sync within 600 seconds will by passed automatically\n";
$this->logConsole($msg);
@@ -285,7 +291,7 @@ class Xero {
$msg .= "wp sync_users --mininterval=6000 \n";
$msg .= "6000 means those users synced within 6000 seconds will be bypassed \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 .= "---------------------------------------------\n";
$this->logConsole($msg);

+ 26
- 17
js/bts_timesheet.js Voir le fichier

@@ -314,7 +314,10 @@
return;
var table = $(this).closest('div.divTable');
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();
});
@@ -907,6 +910,7 @@
if (!confirm ('copy entire week to next week? '))
return;
var jobs = [];
var job_els =[];
$('div.week1 >div').each(function(i,e){
var date = new Date($(e).find('span.weekday').data().date);
var strDate = format_date(date); //yyyy-mm-dd
@@ -917,16 +921,13 @@
var el = $(e).closest('div.divTable');
if (el.is(":visible")){
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();
});
@@ -942,9 +943,13 @@
}
if (!confirm ('copy to next week'))
return;
var jobs_el = [];
$('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();
});
@@ -958,9 +963,10 @@
var tb = $(el).closest('div.divTable');
if (tb.is(':visible')){
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){
@@ -984,7 +990,7 @@
data.finish = format_date_time(f);
}
var newj = new Job(data);
newj.mark_highlight_me(1000);//for 1 second;
return newj;
}
function is_valid_date_str(val){
@@ -1043,13 +1049,13 @@
if (response.status =='success'){
var job_els = [];
response.jobs.forEach(function(job){
console.log('loading job... %o', job);
//console.log('loading job... %o', job);
var o = new Job(job);
job_els.push(o.el);
});
show_jobs(job_els);
show_jobs(job_els, 'in-ajax=true');
//filter it if reqired
do_filter_workspace();
debounced_filter_workspace();
}else{
alert('error loading job');
}
@@ -1058,11 +1064,14 @@
}
function show_jobs(job_els){
function show_jobs(job_els, in_ajax){
if (job_els.length >0){
$('div.workspace').append(job_els);
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){
@@ -1106,8 +1115,8 @@
});
$(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(){
var staffs =[];

+ 3
- 1
ts.php Voir le fichier

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

Chargement…
Annuler
Enregistrer