0

I have this situation when there are 2 users A and B and they send friend request simultaneously to each other for adding as friend. The data model to support this relationship has columns inviter_id and friend_id and a status.

Since both of them sent request to each other together, I am facing problem in deciding who should be stored as Initiator of request as data may get dirty in database with both as initiator of same relationship since they happened absolutely concurrent.

In other languages , there are construct for Locks which can handle this by putting one to wait while other is served. I don't know how to implement this in PHP and Apache .. please advice on this..

5
  • Actually I don't understand your problem. You've got two friend requests, both users are Initiators. You might want to automatically resolve the two requests by checking if the other user is an initiator as well. Commented Apr 7, 2013 at 17:38
  • @hakre - I stated the problem with consideration that these request happen parallely and so they won't know about each other till the database ends up creating a circular dependency i.e storing both as initiator. But, from answers I realise that this is probably not possible that 2 request can come parallel from apache as there will be always a timestamp lag .. Commented Apr 7, 2013 at 17:44
  • Even though, this must not be a problem. Both users will "get" the notifaction that there was a friend request. The moment you create/handle that notification you can check if the other user did request friendship as well and then automatically accept both. Commented Apr 7, 2013 at 17:46
  • So, to handle these notification, I should be probably be using some application wide Queueing for request which would in turn ensure that these problems don't arise.. Commented Apr 7, 2013 at 17:51
  • 1
    Even much simpler. Next time a user checks because logging in (e.g. user got the email), you can just do that. One of the two users will login first. So you can just check, tell the user that the request was accept and all is fine and dandy. Commented Apr 7, 2013 at 17:52

2 Answers 2

3

You should make it like this:

A - Sends invitation
if B is Trying to add A as a friend (while A is already invited B) Then B automaticly accepts A's invitation

Sign up to request clarification or add additional context in comments.

Comments

2

Technically you won't get these request "at the same time", which means id you check the timestamp for request at the sane resolution (like seconds or even milliseconds) you will be able to simply tell which one did that first.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.