Forum Discussion

samhigton's avatar
11 years ago

Checking if a single user is online

I'm trying to implement a widget that shows wether the author of a post is online or not.

 

Now I've checked with support, and apparantly there isn't an api call to check wether a user is online or not, but there is '/users/online' which lists all of the users currently online.

 

I've used this to come up with a solution, but I'm not sure if it's the most efficient way of going about things. What I'm essentially doing is fetching the list of all users online, and then checking against that list to see if the user I need is in it. It's running fine at the minute, but I'm afraid it might start causing performance issues when we have more than just a few users online. 

 

Has anybody else tried to tackle this problem, and if so, how did you go about solving it?


  • samhigton wrote:

    I'm trying to implement a widget that shows wether the author of a post is online or not.

     

    Now I've checked with support, and apparantly there isn't an api call to check wether a user is online or not, but there is '/users/online' which lists all of the users currently online.

     

    I've used this to come up with a solution, but I'm not sure if it's the most efficient way of going about things. What I'm essentially doing is fetching the list of all users online, and then checking against that list to see if the user I need is in it. It's running fine at the minute, but I'm afraid it might start causing performance issues when we have more than just a few users online. 

     

    Has anybody else tried to tackle this problem, and if so, how did you go about solving it?


    I think users/online is going to pull in FAR too mcuh data if things get busy.

    Based on the user id of the author you could use REST to retrieve the value:

    <last_visit_time type="date_time">2014-01-03T00:14:22+00:00</last_visit_time>

     You can see everything available in the user object by visiting your Community URL/restapi/vc/users/id/XX

     

    I'd simply take the current time, check it against the last visit time, and if it's within 5-10 minutes mark them as online.

     

    If you narrow the REST call down to just that object you're pulling a single piece of data, which is much better for security and for your server instance ;)


  • samhigton wrote:

    I'm trying to implement a widget that shows wether the author of a post is online or not.

     

    Now I've checked with support, and apparantly there isn't an api call to check wether a user is online or not, but there is '/users/online' which lists all of the users currently online.

     

    I've used this to come up with a solution, but I'm not sure if it's the most efficient way of going about things. What I'm essentially doing is fetching the list of all users online, and then checking against that list to see if the user I need is in it. It's running fine at the minute, but I'm afraid it might start causing performance issues when we have more than just a few users online. 

     

    Has anybody else tried to tackle this problem, and if so, how did you go about solving it?


    I think users/online is going to pull in FAR too mcuh data if things get busy.

    Based on the user id of the author you could use REST to retrieve the value:

    <last_visit_time type="date_time">2014-01-03T00:14:22+00:00</last_visit_time>

     You can see everything available in the user object by visiting your Community URL/restapi/vc/users/id/XX

     

    I'd simply take the current time, check it against the last visit time, and if it's within 5-10 minutes mark them as online.

     

    If you narrow the REST call down to just that object you're pulling a single piece of data, which is much better for security and for your server instance ;)

    • samhigton's avatar
      samhigton
      Guide
      Thanks for your help, this looks to be a much better way of doing things. From what I can gather, I'm pretty sure that's how the '/users/online' api call is calculating it anyway.