Note that there are some explanatory texts on larger screens.

plurals
  1. POBatch processing notifications of job tracking
    primarykey
    data
    text
    <p>At the moment we're using three nested foreach loops to get the information to run the batch. However I'm fairly sure we could get the information with a single MySQL statement with joins and sub-queries.</p> <p>We have about 30 categories with 2000 users. Our aim is about 100 categories with 100000 users though so obviously the foreach loops are not ideal (even now they take about a minute to run).</p> <p><strong>Circumstance:</strong> Users want to be notified if there is work available for a trade they can do in a certain area</p> <p><strong>Goal:</strong> Batch process (daily, weekly, etc) notifications to be put in outbox</p> <p><strong>Technology:</strong> PHP, MySQL</p> <p><strong>What I have so far:</strong></p> <p><strong>Database:</strong></p> <pre><code> "table.notification_options" : [id][user_id][category] "table.user" : [id][user_id][method_of_contact][contact_frequency][center_of_work_area_long][center_of_work_area_lat][distance_from_center] "table.work" : [id][post_date][longitude][latitude][category] </code></pre> <p><strong>Code:</strong></p> <pre><code>foreach user{ foreach category tracked{ foreach job in category posted &lt;&gt; $current_date-$batch_frequency{ if job inside workspace{ notify_user(job); } } } } </code></pre> <p>The desired result is an array of arrays of job_ids with user_id as the key [user_id]=>{jobs}</p> <p><strong>e.g.</strong></p> <pre><code> { [user1]{ job1, job4, job28 }, [user34]{ job3, job4, job34, job78 } { </code></pre> <p><strong>EDIT:</strong></p> <p>I've got it a bit more efficient where I can select all the jobs for one user. But it still requires a foreach user.</p> <pre><code> $category_id = get_category_from_notification_options($userid); $user_distance = get_user_work_distance($userid); "SELECT DISTINCT work.ID as workID, ( 6371 * acos( cos( radians(-46.409939) ) * cos( radians( jobs.lat ) ) * cos( radians( jobs.lng ) - radians(168.366180) ) + sin( radians(-46.409939) ) * sin( radians( jobs.lat ) ) ) ) AS distance FROM work,user WHERE work.categoryID == $category_id HAVING distance &lt; $user_distance ORDER BY distance"; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload