Comments (5)
I have played around with current api system and I was able to reduce it to a little less than 1 minute. This time I only pull first 25 csrs. The time that burns the most is at looping stage for fetching 'plannedHours'. I know that I can get the collection of keys in array. Is there any way that I can pluck the one column value (for my case 'plannedHours') after find()? What I looking for is to fetch only 'plannedHours' values in array and sum those values. This would reduce significant time.
Thanks,
Ryan
$results = [];
$count = 0;
foreach($csrs as $csr_id => $csr_name){
$results[$count]['csr_id'] = $csr_id;
$results[$count]['csr_name'] = $csr_name;
$activeJobIds = $this->paceStartSql()
->filter('@csr', (int) $csr_id)
->sort('@job', true)
->find()
->filterKeys(function($key){
return preg_match('/^[0-9]{6,}$/', $key);
})->keys();
$active_dockets = count($activeJobIds);
$results[$count]['active_dockets'] = $active_dockets;
$parts = 0;
$hours = 0;
if(count($activeJobIds) > 0){
$jobPlans = $pace->jobPlan
->filter(function($xpath) use ($activeJobIds){
$c = 0;
foreach($activeJobIds as $activeJobId){
if($c == 0){
$xpath->filter('@job', $activeJobId);
$c = 1;
}else{
$xpath->orFilter('@job', $activeJobId);
}
}
})
->filter('@activityCode', $this->prePressJobPlanCode)
->filter('@plannedHours', '!=', 0)
->find();
foreach($jobPlans as $jobPlan){
$hours += $jobPlan->plannedHours;
}
$jobParts = $pace->jobPart
->filter(function($xpath) use ($activeJobIds){
$c = 0;
foreach($activeJobIds as $activeJobId){
if($c == 0){
$xpath->filter('@job', $activeJobId);
$c = 1;
}else{
$xpath->orFilter('@job', $activeJobId);
}
}
})
->find()
->count();
$parts += $jobParts;
}
$results[$count]['total_parts'] = $parts;
$results[$count]['booked_hours'] = $hours;
$count++;
}
from pace-api.
We usually do queries on data over the database, which is much much faster. Especially for inquiries through more than one object.
@robgridley wrote: "I hate the Pace database. Who ever named those columns should be flogged in the street. At least come up with a consistent naming scheme for relationship keys!" - it is big TRUE
But we are using phpstorm that make things much easier:
https://blog.jetbrains.com/phpstorm/2014/11/database-language-injection-configuration/
from pace-api.
Hi there,
I found 'pluck()' in KeyCollection class. But it didn't cut any time on fetching 'plannedHours'... I guess I should close this ticket for now..
from pace-api.
It does not really matter what you do in PHP, because your PHP code is not the bottleneck. It is the repeated API read object calls which are slow. It is known as an "N+1 problem". Unfortunately, the API does not allow you to read multiple objects at once or fetch only the properties you are interested in.
I agree with @radoslavius. This is a situation where querying Postgres directly—at least for summing the planned hours—would perform a lot better.
from pace-api.
Thanks for your answer, robgridley.
Could it be possible for you to add additional API feature that allows users to run raw psgresql queries?
e.g. $job = $pace->select('SELECT * FROM jobs WHERE job = ? ', [123]);
from pace-api.
Related Issues (20)
- re: manufacture qty is not saving HOT 7
- JobNote - jobPart is not updating HOT 9
- how to catch the soap error !! HOT 4
- Pagination is not working in my code HOT 5
- the package doesn't seem to work with php version 7.3.4 HOT 3
- How to retrieve all jobs HOT 1
- Support for loadValueObjects under the Find Object Aggregate API Service
- Is it possible to import part into existing estimate via API? HOT 1
- Pass variable into grouped filer HOT 3
- FileAttachment Fun HOT 2
- Report Service string/integer problem HOT 5
- User Defined Object Issue HOT 3
- calling Actions? HOT 2
- Is it possible to convert an estimate to an existing job, possibly using InvokeAction HOT 1
- How do you set an option for a EstimateFinishingOp HOT 1
- Shit. 32.01-3361 broke $image->getContent(); HOT 3
- Updates PHP to 8.1.10 can't get objects HOT 2
- doctrine/inflector version 2.0 HOT 2
- How do get error for api calls in transactions?
- FindObjects similar method HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pace-api.