This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I am not sure in which forum i am supposed to post this question, i am assuming it as a performance issue and hence posting it here.
We have an application where we need to share some video playlists to users.We send the URL of the video to the users through emails and most of the times same URL is shared to many users(we have a textbox kind of thing where multiple email ids are entered and an "e-mail is sent" message displayed once all the emails are sent). The users will open the mail and click the URL to access the playlist.But there is a catch , when the user clicks on the link from email he is redirected to login page where his email id is pre -populated in user name(as non editable text). In our current implementation we are generating a random key for each of the email ids and appending the key to the URL.Based on that key we populate the email in login page.But as you can imagine as number email ids increases the generation of key for each user is taking a lot of time and the process of sending email is delayed.This approach was already implemented by my "seniors" and they are not willing to change it.But i just cant stop thinking is there any better way to accomplish the above task without generating a seperate key for each email id and yet somehow we need to know form which email that URL is being accessed.
But as you can imagine as number email ids increases the generation of key for each user is taking a lot of time and the process of sending email is delayed.
Why is this? The amount of time it takes to create a key should not depend on the number of email addresses there are; it should be constant. Also, instead of creating the key every time you send an email, you could create it just once when the user registers (and maybe have a background job that creates new keys every so often if that is deemed necessary).
I'm guessing the key is an encrypted or hashed version of the email address? How many email addresses are we talking about? And how long does it take to generate these keys? And, taking a step back, compared to sending out the emails I would imagine that generating the keys takes a miniscule amount of time. Not to mention that -this being email- it shouldn't really matter whether they go out a minute sooner or later, yes?
Thanks Ulf for the response.
I think I am not able to convey my point properly.Let me gave an example , suppose the URL of the playlist of I need to share is :
I have an admin who wants to share this URL via my application , my application has an UI which accepts comma seperated email ids and the UI also has the text area where he can paste the above URL, and clicks on "Send" button.Till the mails are sent "Sending.." message is shown.Suppose 2 email ids are entered 2 different keys are generated and is appended to the actual URL , so the actual URL that would be sent to say email@example.com and firstname.lastname@example.org is:
www.mywebsite.com/videos/myplaylist1+someKey (for email@example.com) and
www.mywebsite.com/videos/myplaylist1+someOtherkey.( firstname.lastname@example.org) so on.
we store both email and key in different columns of a database table.
So when the user(the one who recieved the email) clicks on the URL , the user is directed to login page with the email prepopulated in the username textbox based on the key appended,
So the thing is for every email id we are generating a unique key.So as the number of email ids increase the time taken to generate a key for each and every email id is taking time. As far as i know the whole approach of this design might be flawed.But i cannot think of any other way of prepopulating the email id.Hope I am a litlle more clearer now.
Joined: Mar 22, 2005
If the email address is the username for the login, then I don't see why the key could not be generated and stored in the DB right when the user account is created. There should not be a need to generate it over and over again each time a mail is sent.
I'm still not clear what the performance issue is, exactly. Again: how long does it take to generate the key on the fly? How many email addresses can someone possibly enter manually?
But taking a step back: making a web user wait until such an operation is finished is not a good way to design a UI. What if the browser times out the request? Or the server? What if the user accidentally closes the page? The usual approach to this would be to start a background job, which could then either send an email to the admin once it's done that contains all the details of what happened, or there could be a web page the admin can go to that summarizes the background activity while and after it's going on.
The point of generating key while sending the mail rather than when creating the user is that , this feature is basically to market the site , so the email ids which would be entered are the new ones and do not exist in the list of current users.The user may or may not access the website by clicking the link sent in email.So we have no option but to generate keys seperately.
We provide a temporary login with a temporary role , through which he can access only that particular playlist , however on full time registration he can access all the playlists .And the time tken is too long because we are doing lot of validations like if the email id is valid , there are no duplicate email ids .So the key generation might not be the "only" reason for the delay.Basically I am looking for a better approach where I can prepopulae the email id in login page.
Joined: Mar 22, 2005
Then I would advise not to do this while the admin waits for the web page to finish, and instead push it into the background as I described two posts back.