Entry tags:
where to put functions
So, I am currently in the first stages of working on http://bugs.dwscoalition.org/show_bug.cgi?id=1574 ( "Last active entries" module) and it's actually going quite nicely :)
However, I am a bit stumped on where to put a function I need. Namely, I need a function that, depending on what journal the module is in and who is viewing it, returns the last x active entries in that journal (maybe not the full Entry objects, though, still working on that).
My first thought was cgi-bin/LJ/User.pm , as it would be good to have $u->get_recent_active($remote) or something like that. But now I am leaning more towards putting it in cgi-bin/DW/Logic/LogItems.pm , which has the functions $u->watch_items and $u->recent_items . However, my idea only semi-fits the module description.
Or maybe it should be in cgi-bin/LJ/S2.pm?
Yes, I am still confused by where to put stuff. Any ideas?
However, I am a bit stumped on where to put a function I need. Namely, I need a function that, depending on what journal the module is in and who is viewing it, returns the last x active entries in that journal (maybe not the full Entry objects, though, still working on that).
My first thought was cgi-bin/LJ/User.pm , as it would be good to have $u->get_recent_active($remote) or something like that. But now I am leaning more towards putting it in cgi-bin/DW/Logic/LogItems.pm , which has the functions $u->watch_items and $u->recent_items . However, my idea only semi-fits the module description.
Or maybe it should be in cgi-bin/LJ/S2.pm?
Yes, I am still confused by where to put stuff. Any ideas?
no subject
mysql> explain select journalid, nodeid, datepost
from talk2 where journalid = 35 order by datepost desc limit 5\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: talk2
type: ref
possible_keys: PRIMARY,journalid
key: PRIMARY
key_len: 4
ref: const
rows: 36862
Extra: Using where; Using filesort
1 row in set (0.00 sec)
If it does, you can't use it. See that "using filesort" bit? Yeah, that means it's doing an awkwardly large scan of data: for this query, every single comment on a journal has to be loaded from disk and then sorted.
As a general rule, you must have an index on the data you're searching and ordering on. In this case, there's no index that covers datepost so there's no way to do a "sorted by time" search of the comments using talk2.
I can't think of any other "easy" way of doing it, either. Sorting by the logprop "commentalter" won't work for similar reasons (you'd have to load every logprop for every entry and sort).
Only/best way to do it is probably going to involve very painful ALTER TABLE statements on log2 to add (commenttime) and then INDEX (journalid, commenttime) and then doing your sorts based on that... but that's pretty painful. (But probably the best way...)