The short version:
What's the best way to que thousands of rows, with ability to process each of those rows individually as needed (view, update, delete)
The details:
This is with regards to a part of my web app -> sending messages to an API...
I have the following tables
outbox (user_id, name, address, message, etc ) - the table that keeps records of all message sent. each row is 1 recipient
broadcast (id, user_id, name, message, address, stat[pending,sending,sent,failed], etc) - each 1 broadcast row is a mass message that can be related to 1 to 20,000 (or more) recipients in the outbox table
(in case i get critiqued... i keep a copy of the user_id, name and message for important purposes)
PROCESS:
1) User creates broadcast sessions
2) User selects contact group to send
3) User press SEND
At this point web app pulls all the individual recipient data from the contact group selected and sends it to que... <-- this is the part i'm struggling to optimize ..
At the moment what I do is upon sending, the I INSERT all the recipient data in the outbox that way i have individual rows i can monitor, query, search from, and even cancel/delete
This is fine for most use case where there are usually less than 1000 recipients .. but i got to a point where i will be needing to send to 10,000 recipients or more ... and im worried about script/sql timing out on writes.. or wasting auto incremented id numbers in the outbox table for broadcasts that are cancelled (i essentially have to delete unsent rows leaving huge gaps in the primary ids)
So I was thinking of holding the huge recipient list somewhere in a queued state, and then writing it to outbox table only when I send it to api (@ around 10 rows / second) because this way i prevent clutter in my outbox table and i dont need to do a massive 10,000 + rows INSERT into the table w/c may cause timeouts. (then again i still have to write that 10,000+ rows somewhere..hmmm)
So do idea is to dump all that into a single source location (eg 1 txt file) and load it from there
Anyway my options are:
OPTION 1: Use Flat File
-> I would simply write all rows in a text file (in array format for convenience) and load that into PHP
OPTION 2: Use Array stored in a single full-text type column in the broadcast table
-> I would simply store all recipients in a column, in array format
The only problem that I see here is that everytime i need to access some rows I have to load a huge chunk of data and parse through it (easy w/ array find(id) ) just to view or make updates to rows, or when I send a few rows to the outbox table.
OPTION 3: Quit making my life too hard and just stick w/ using the outbox table.
Any thoughts?