How google doc sync two document at the same time? - javascript

I am making a cooperation application like google docs, but I found this is different to do on the web. The problem is, when the user typing, another user should see the update at the same time. But what actually behind the screen? Is that when the user have an action, it sent a http request, and write into database. At the same time, another user get the action from database, and rendering the result that the user just type. If use this way to implement, the database need to keep read and write.....apart from this solution, how can I sync two people work on the fly? Thank you.

Check out something like this http://pusherapp.com/
Or http://www.tornadoweb.org/
Both are good at real time pushes without constant AJAX requests that will put a lot of strain on your server

Related

AJAX - How can I build a notification system, that is constantly getting updated, without slowing down my website too much?

I am a beginner to web development, and I am trying to do a notification system with AJAX and jQuery.
In my web application, I have a comment system where you can mention another user. After a comment mentioning a certain user has been written, a new entry on my notifications table will be added, containing the comment, the id of the user who commented and the id of the user(s) who will receive the comment. After the notification is stored in the database, I want the person that was mentioned to receive the notification.
To that effect, I decided to use AJAX. Using the setTimeout() method, I am sending an AJAX request to the database every 2 seconds, and with that, I can display the notifications visually to the user that is meant to receive them.
My only concern is that this will slow down the site once I connect it with a server.
So, I was looking for a way that would allow me to implement a notifications system without slowing the site too much, since the one that I am using currently doesn't seem very efficient.
I would appreciate any help.

Proper way to process Large number of records in React or Java

I have front end in ReactJS and backend api in Spring Boot. I have to show a drop down list with records from Api.
The scenario is i get a list of Users Ids from one end point, then for each record i have to call another api end point to get address details associated to that user ( it may have large number of records), the drop down is name of address.
My problem is if i loop through all records and get the address details, it will time out and take forever.
Can anyone suggest me the correct way to do it, Java or JavaScript.
I have read a little about observable, observer etc. but i did not get anything. Is there any concept of updating an object continuously.
Thanks
The shorter the distance the faster it can go. If you do this client side, the server has to send data on the network and then the client can process it. The best way would be to write a SQL query that does the right joins to get the data quickly. Send the processed data to client.
One good way to handle data is by implementing some kind of a pagination. You don't need to display all of the data in one go and it will be expensive to do so. For instance, if you have 1000 items on a list which you want to fetch, you could do it by 10s or 20s depending on your preference. This way, you could minimize the number of queries. Thus, making it much faster.
Here is an example of doing that on React JS. I'm only tapping into a Fake Online REST API
Hope this helps.

AngularJS and MySQL real-time communication

I have built a web application using AngularJS (front-end) and PHP/MySQL (back-end).
I was wondering if there is a way to "watch" the MySQL database (without Node.js), so if one user adds some data to it, the changes are synced to other users too.
E.g. I know Firebase does that, but it's object oriented database and I am unable to do the advanced queries there like I do with SQL.
I was thinking to use $interval and $http and do ajax requests, so that way I could detect changes in the database. Well, that's possible, but it'll then do thousands of http requests to the server everyday and plus interpret php on each request.
I believe nothing is impossible, I just need an idea to do this, which I don't have, so that's why I am asking for a help here.
If you want a form of "real-time communication" you'll likely have to incorporate some form of long-polling from the client. Unless you use web sockets, but that's a big post about a bunch of different things. You're right to be concerned about bandwidth and demand on the DB though. So here's my suggestion:
If you don't have experience with web sockets then log your events in a separate table/view and use the pub/sub method to subscribe entities to an event, and broadcast that event to the table. Then long-poll against the watcher view to see when changes may have occurred. If one did occur then you query for the exact value.
Another option would be to use some query system with "deciders" that hold messages. Take a look at Amazon's SQS platform for a better explanation of how this could work. Basically you have a queue that holds messages and a decider chooses where to store the message using some hash or sorting method (to reduce run time). When the client requests an update, the decider finds any messages that would apply based on the hash/sort and returns them. Then you just have to decide how and when to destruct the messages.
The second option would require a lot more tinkering though, so it's really about your preference. I think what you'll find the difficulty to be is that most solutions have to deal with the fact that the message has to be delivered 1 or More times and you'll need to track when someone received the message and if it can now be deleted from the queue/event table or if you still need to wait. Otherwise you'll consume a lot of memory.

Get Facebook user name with javascript SDK and app access token

I've coded some php which retrieves facebook user ids, stored in my database, and then goes on to request their user names. It all works fine, however this process adds an additonal 1.8 seconds to my pageload, which I would like to avoid if possible.
So I rebuilt the code, and added some javascript which looks for the user ids and then requests the user names. This method runs a lot faster and my page load is 1.8 sec shorter. However in order to make it work I'm adding my app access token to the javascript, which ofcourse is a security black hole
The javascript fb.api call looks like that at the moment
FB.api('/'+userid, {access_token : 'appAccessToken'}, function(response) {
userNameSpan.text(response.name);
});
Is there any other way I can make this work, without falling back to the pure server-side solution which is awfully slow?
I'm getting no answers at all to my questions lately. Anyway, the only other solutions I can think of are ajax calling the php file, which will be requesting the user names itself, or storing the user names in the database along with the user ids.
The ajax solution is problematic for a lot of reasons, mainly because the platform is joomla and the php is a custom module, which means that I will have to either call the file outside of the joomla framework (security issues arise) or build my own helper file for the custom module in order for it to work with the com_ajax component of joomla, which ofcourse is a timesink.
The database solution has the downside that the usernames will not be dynamic, meaning that if a user chnages his/her user name after he/she has been added in the database, the change will not be available to me. I guess I could also store the time the user was inserted in the database and check how much time has passed, and perform a facebook request for his/her username only after a predefined time has passed, and then updating the database if the username has changed. Not quite dynamic, but close enough
If any1 has any other ideas, please don't be shy
Although I'm gonna go for the database solution, I found another solution that can decrease the pageload significantly.
Instead of making an api call for each user, you can do a batch call, requesting info about many users in one call. It is explained here https://developers.facebook.com/docs/graph-api/making-multiple-requests
That would cut down my calls from 6 to 1. However since reading up a bit about facebook names, I realized they do not change that often any more, so the database solution is better for my case

How can I send "push notifications" to a specific users webpage?

I'm not really sure where to begin.
I'd like to be able to update a users current page when another user either updates my database or sends a specific GET/POST request (I could write it either way).
I was thinking server sent events but I made a quick test using my php server and realized a couple things. First I would need an event loop based server because using php I'd have to create a loop to keep checking my database for a specific change. Second I realized this would be very server intensive so I should look into another method.
So to explicitly ask my questions...
Is it possible to update a users current page when someone else sends a GET request to a php file on my server? How?
If I need an event loop based server what is my best option? node.js?
Is this possible with sockets if not with SSE? SSE makes more sense because I'm not looking for any user feedback.
Thanks
Websockets and something like SignalR for ASP.Net could help you. Check out the options here
You can use Ajax too.
Like this : Here

Categories

Resources