php - How to setup an efficient way to save volatile information to a database -
i working on web service following output (which partially works) result api request.
request
i built api accepts following request: post
http://server.com/v1/requests/"
parameters send on in message body.
response
status-code: 200 ok
{ "transaction_id": "12345", "status": "processing" }
table: requests
this creates new request on server in table called requests
. table consists of fields (simplified):
transaction_id -> string status -> int
i have table users in system
table: users
this table holds info users in system registered.
user_id -> string latlng -> float
search users nearby request location
the algorithm have follow:
- when send request server, starting search nearest 3 users in range of request made. search being performed on users table , returns array of users near location searching (code not being displayed, works fine).
- this array of users sorted distance (nearest farest) know users close request position.
- i send push notification these 3 users asked if can respond request. can choose accept or decline. decision should saved database
when make request particular request, create following response:
response
{ "transaction_id": "12345", "responders": [ { "user_id": "r001", "dispatch_time": "1234" }, { "user_id": "r002", "dispatch_time": "1235" }, { "user_id": "r003", "dispatch_time": "1236" }], }
this workflow clear me. totally unclear me how need implement table structure/algorithm efficient. questions are:
- where store information 3 responders have been found database query? can think of ways @ moment: 1 adding additional fields in
requests
table each holduser_id
. think of like:
|transaction_id|status|user_id_1|user_id_2|user_id_3|
|12345 |1 |u100 |u200 |u300|
i update same table entry each user responds request , @ end have 1 entry in table.
the other way thought of, be:
|transaction_id|status|user_id|
|12345 |1 |u100
|12345 |1 |u200
|12345 |1 |u300
this seems somehow strange me. don't blow whole table data @ end have 3x amount of data? how done in efficient way?
so right algorithm/structure receive output wishing for?
Comments
Post a Comment