Fix the "Grab title" button on the "Submit a post" page, as well as thumbnail generation for newly posted links and uploads to return a response immediately, work on the grabbing or generation in a new greenlet thread, and deliver the finished title or thumbnail to the browser via SocketIO. This makes the user interface feel more responsive, allows other requests to be serviced simultaneously, and prevents long response times when the website being grabbed from or thumbnailed is slow.
These changes include:
Logging for socketio messages which includes the data sent with the event. Assign the logger flask.app.socketio the level of DEBUG to enable this.
Lazy loading of all thumbnails, not just the ones being generated. This allows the browser to start rendering the page before all the thumbnail images are loaded, which will make it feel faster if either the user's internet or your image hosting service is slow.
Much faster thumbnail generation, mostly achieved by not making the BeautifulSoup HTML parser guess at the encoding when looking for images in requested webpages (a 50x speedup) and not making it parse an entire webpage when it just needs to look at the <head> element.
A few gevent.sleep() calls in cpu-intensive loops, to allow other greenlets to run.
Fix the "Grab title" button on the "Submit a post" page, as well as thumbnail generation for newly posted links and uploads to return a response immediately, work on the grabbing or generation in a new greenlet thread, and deliver the finished title or thumbnail to the browser via SocketIO. This makes the user interface feel more responsive, allows other requests to be serviced simultaneously, and prevents long response times when the website being grabbed from or thumbnailed is slow.
These changes include:
flask.app.socketio
the level ofDEBUG
to enable this.BeautifulSoup
HTML parser guess at the encoding when looking for images in requested webpages (a 50x speedup) and not making it parse an entire webpage when it just needs to look at the<head>
element.gevent.sleep()
calls in cpu-intensive loops, to allow other greenlets to run.