News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Inserting posts using createPost

Started by kai920, December 13, 2009, 03:29:13 AM

Previous topic - Next topic

Arantor

* Arantor stretches brain a bit.

Oh, I remember now.

log_boards is for actual read-status, log_mark_read is for when the user has marked a board read.

Now I think about it again you don't strictly need to mark the board read anyhow. It's only on the front page and message index (for child boards) it's actually an issue.

kai920

Yeah you're probably right, I shouldn't bother with log_mark_read. I don't need to deal with log_boards either then by the sounds of things?


So (back to #1).... is there an efficient way to keep my posts sorted by last post/reply date? I don't understand how it came to be sorted like this:




(back to #2) - still haven't figured out the weird spacing issue. Is there a way to 'simulate' a post modification?

Arantor

It's ordered like that because it's done by id_msg and id_topic, i.e. in order of creation in DB instead of in order of time.

I also seem to recall something in the board table about the most recent topic in that board for caching.

You'd have to replace the queries for board index (Subs-BoardIndex.php), message index and display to include ORDER BY m.poster_time when m is the messages table (I don't *think* you need any more than that, but I'm not 100% sure)

kai920

#43
If I hard code line 417 of MessageIndex.php to be ORDER BY last_poster_time DESC it seems to work. Perhaps I can modify the board sort methods mod to achieve what I need.

Do I really need to modify Subs-BoardIndex and Display as well?


edit: success, I think. I edited the code in the mod inside MessageIndex from




        // Default sort methods.
        $sort_methods = array(
                'subject' => 'mf.subject',
                'starter' => 'IFNULL(memf.real_name, mf.poster_name)',
                'last_poster' => 'IFNULL(meml.real_name, ml.poster_name)',
                'replies' => 't.num_replies',
                'views' => 't.num_views',
                'first_post' => 't.id_topic',
                'last_post' => 't.id_last_msg'
        );



to




        // Default sort methods.
        $sort_methods = array(
                'subject' => 'mf.subject',
                'starter' => 'IFNULL(memf.real_name, mf.poster_name)',
                'last_poster' => 'IFNULL(meml.real_name, ml.poster_name)',
                'replies' => 't.num_replies',
                'views' => 't.num_views',
                'first_post' => 't.id_topic',
                'last_post' => 'last_poster_time'
        );



And the result is attached.

Arantor

If you want to fix the board index, yes, Subs-BoardIndex.php will need fixing.

Display.php is only an issue for the previous/next thread links in the lower right of the display. If you have that disabled, it can be ignored.

kai920

Quote from: The Grinch on December 18, 2009, 11:32:16 AM
If you want to fix the board index, yes, Subs-BoardIndex.php will need fixing.
Does board index = index.php? (ie. the page that displays a list of the boards)

Quote
Display.php is only an issue for the previous/next thread links in the lower right of the display. If you have that disabled, it can be ignored.
AH, hmmmm... if I only 'fix' MessageIndex, then when I browse prev/next in Display it won't "match up" to the MessageIndex, yes?

Arantor

Yeah, board-index is the front page. Subs-BoardIndex.php also handles child boards in the thread display too.

And yeah, the previous/next won't tie up otherwise.

kai920

Quote from: The Grinch on December 18, 2009, 11:37:15 AM
Yeah, board-index is the front page. Subs-BoardIndex.php also handles child boards in the thread display too.

Ah.. I see *lightbulb goes off in head* - it's the "Last post by...." on the board index.

kai920

Quote from: Arantor on December 18, 2009, 11:37:15 AM
Yeah, board-index is the front page. Subs-BoardIndex.php also handles child boards in the thread display too.

And yeah, the previous/next won't tie up otherwise.

Do you think you could spare a few minutes to look into these 2 queries? I tried for a long time and could not get it to work. If you don't have time, I totally understand... :) 

Then, #1 and #3 would be solved, and I just need to see what's up with #2 in the first post.

Arantor

Not sure what, exactly, you need me to do?

kai920

I am referring to this, I think:

Quote from: Arantor on December 18, 2009, 11:11:48 AM
You'd have to replace the queries for board index (Subs-BoardIndex.php), message index and display to include ORDER BY m.poster_time when m is the messages table (I don't *think* you need any more than that, but I'm not 100% sure)

Arantor

Ah...

Thing is, it's not just a straight query now I look at it again. A fair amount of the work is also done after the event in the PHP itself.

How many boards are we talking about? (It only needs one fresh post in the board(s) you've imported into to reset the board index. MessageIndex is a bit trickier, as is Display.php)

kai920

I only have a total of 10 boards, so not that many really. Maybe it's not worth the effort and trouble - time to leave this as is...

As for #2, the extra spacing issue - is there a way for me to manually simulate an edit and save of a post?

Arantor

Not sure there is; it seems to be down to something in it being sent to the browser and back that fixes it - not sure what :(

For 10 boards, as I said, just a new board in each would fix the board index. Fixing up the message and display pages is a little more tricky - the query is a particularly gruesome one in both cases since it also figures out about sticky topics at the same time.

The problem is that I don't think it does a join from the topics to the messages table, meaning you'd have to do that first, which would no doubt apply a performance hit.

kai920

#54
Yeah I'll be happy with the way it is now as far as the "last post" goes...

I just need to take a deeper look at the spacing issue.

edit: think I'll just edit a few of the problem posts with the spacing problem and use this hack to take out the "last modified" text: http://www.simplemachines.org/community/index.php?topic=344737.msg2330314#msg2330314

kai920

#55
Quote from: kai920 on December 18, 2009, 11:23:37 AM
If I hard code line 417 of MessageIndex.php to be ORDER BY last_poster_time DESC it seems to work. Perhaps I can modify the board sort methods mod to achieve what I need.

edit: success, I think. I edited the code in the mod inside MessageIndex from




        // Default sort methods.
        $sort_methods = array(
                'subject' => 'mf.subject',
                'starter' => 'IFNULL(memf.real_name, mf.poster_name)',
                'last_poster' => 'IFNULL(meml.real_name, ml.poster_name)',
                'replies' => 't.num_replies',
                'views' => 't.num_views',
                'first_post' => 't.id_topic',
                'last_post' => 't.id_last_msg'
        );



to




        // Default sort methods.
        $sort_methods = array(
                'subject' => 'mf.subject',
                'starter' => 'IFNULL(memf.real_name, mf.poster_name)',
                'last_poster' => 'IFNULL(meml.real_name, ml.poster_name)',
                'replies' => 't.num_replies',
                'views' => 't.num_views',
                'first_post' => 't.id_topic',
                'last_post' => 'last_poster_time'
        );



I tested on a full set of posts and the above does not work :(


The first page is fine (sorted by last post time) but every subsequent page seems out of whack. Any ideas why?

Am suspecting it has to do with the query following


// Sequential pages are often not optimized, so we add an additional query.
$pre_query = $start > 0;
if ($pre_query && $maxindex > 0)

Arantor

Not off hand - to be honest this isn't something I'm overly familiar with; I know there is a Custom Board Sort mod which has the foundation for it, and I'm sure there's both a 1.1 and a 2.0 version though they're under different names IIRC>

kai920

Yeah I am using that mod, but it doesn't work since by default it just sorts by id_msg. I've got a bunch of pre-existing posts but am inserting a new bunch of posts which will be dated a few years ago but will have higher id_msgs.

I've been trying to look at the queries but to be honest the INNER and LEFT JOINs are kicking my butt!

Arantor

The problem sounds like last_poster_time isn't being used everywhere for sorting. What order does page 2 turn up in?

kai920

It seems to be sorting by id_topic on all the pages except the 1st and last pages.

From page 2 to 11 it's ascending by id_topic.

From page 12 to 20 it's descending by id_topic.

Page 1 and last page (21) I believe are correct (descending by last_poster_time)

Advertisement: