(03-29-2011 08:34 AM)leefish Wrote: Hmm, I am unsure as to the did as the primary key - I would have thought the user ID, then check to see if they had already downloaded? Table design is a new area for me though, so you are probably right.
Primary keys need to be unique, so if you put it on uid, the user cannot have more than one aid associated with it.
did is an "artificial" primary key.
Personally, I'd put it on aid,uid (ie, a composite primary key), since the pair of columns
uniquely identify each table row (what a primary key should do).
(03-29-2011 08:34 AM)leefish Wrote: I would need to load the session (and the mybb core) - would that have a slowdown effect?
Loading core definitely consumes more resources, but how much is somewhat open to interpretation, and whether it affects you is something you need to find out (in short, if host doesn't complain, you're probably fine). Here's a bit more of a technical explanation.
xthreads_attach.php was somewhat designed to handle two extreme cases which the MyBB attachments.php doesn't do well (as well as a number of other things, but that's irrelevant here):
- very large (i.e. multi-gigabyte) downloads
- many requests (i.e. an image gallery displaying a lot of thumbnails on a page)
For the former case, typically the script will be active for a long time, since the download will take a while to transfer. So if we load the core here, the script will hog that amount of memory for quite some time. This problem can be further compounded with multi-part downloading - eg, user downloads a 2GB file with 10 threads = 10x MyBB cores stay resident on the server's memory whilst the user downloads the file.
If you have no excessively large downloads, then this point isn't a problem.
For the latter case, imagine a gallery 18 thumbnails per page. Loading the core effectively means that a user visiting forumdisplay will cause the MyBB core to be loaded 19 times, instead of just once. Quite a bit more load obviously, but if your host isn't complaining, then this shouldn't be much of an issue. If you're not using something like this, then you don't need to worry either.
There may be a fix for this issue on XThreads' end by directly linking thumbnails rather than serving through xthreads_attach.php - I don't know why I didn't think of it a long time ago. It might be a bit too late to change now (breaks template edits) though there may be a bit of a workaround.
But there's another thing you could do - just simply conditionally define LOAD_SESSION based on whether the user is trying to view a thumbnail or not. May require a fair bit of editing though.