YesNoOk
View in topic context
15 Replies
May 24
2013

Re: User tagging

May 24, 2013, 18:05:55 | by Nightwish
Well, thats as far as I could go really, the script itself fires up an ajax call everytime the user types the @, thats cool for simple queries to text files or simple demo pages but for something real like a forum userbase thats just not possible as it would kill the server. Thats why I end up wrapping the ajax call to be fire up only on focus() , that alone drastically reduced the number of ajax request the script does, the retrieved data gets appended to the DOM so all the sorting and juggling are done on client side which is really a nice plus to have.
But how exactly do you perform the database lookups for the user names?

I know, it's a performance thing - looking up on every letter typed by the user would generate way too many requests, so that's not a solution.

At some point, I had the idea of implementing "lightweight" requests, particularly for requesting json responses. Such a lightweight request would skip all the heavy initializations like loadTheme(), loadBoard() and so on, because this isn't really needed for a simple database lookup. Loading the session, permissions and user data would still be required though, and with some testing, I found out that you don't gain much from skipping a few initializations, so I quickly forgot the idea.

For small forums (probably for the majority of all forums out there) you could simply fetch all username at once and cache them using our caching system - refreshing this cache every couple of hours or maybe every time a new member registers would be enough.

Still, you would need to fetch the username cache when a member performs a lookup and store it somewhere (preferably in the browser to make lookups completely client-sided). With a large member base, the cache could easily be a couple of megabytes in size, but memory isn't really the problem here, it would just generate a lot of traffic.

Quote
I tried the SMF autosuggest feature, perhaps it was me but I didn't find it easy to customize and besides it wasn't designed to work on textareas.
The latter can be done quite easily (just a bit work on the JS). What autosuggest does is that it requires the user to know the first 3 letters of the username - it will only query the database after the first three letters have been typed. This is a reasonable compromise, but with a large member base, the list of names sharing the first three letters can be large enough to present the user a very long list of names.