Ticket #200 (new code bug)

Opened 2 years ago

Last modified 2 years ago

Caching of parsed posts

Reported by: latiass Owned by: latiass
Priority: major Component: forum
Keywords: Cc:
Difficulty:

Description (last modified by latiass) (diff)

I believe there is already a bug touching on the lack of usage of the format column for posts, but this is a bit more specific: using format=html to cache posts that have had bbcode parsed, to make adding new bbcode much less painful. This will reduce load marginally, but with enough requests it could become significant.

Attachments

Change History

Changed 2 years ago by latiass

  • description modified (diff)
  • summary changed from 200 to Caching of parsed posts

Changed 2 years ago by latiass

  • component changed from pokedex to forum

I fail at trac so much.

Changed 2 years ago by latiass

  • owner changed from eevee to latiass
    my @htmlized =  map { $_->id } $c->model('DBIC::Posts')->search({ 'me.format' => 'html' }); # find posts that are HTMLized
    
    my $posts_rs = $c->model('DBIC::Posts')->search({
        -and => [ 'me.threadid' => $id, ( $filter_user ? ( 'me.userid' => $filter_user->id ) : () ),
            ( @htmlized ? ( -or => [
                    { 'me.id' => \@htmlized, 'me.format' => 'html' },
                    { 'me.id' => { '!=', \@htmlized }, 'me.format' => 'bbcode' }
                ],) : () )  
            ],
        },
        { prefetch => [ 'user', { 'lastedit', 'user' } ], order_by => 'me.time ASC', offset => $skip, rows => $perpage + 1 }
    );

Wow. But that works. However, this requires modification of the schema; posts' primary key must now be PRIMARY KEY ( id, format ), because we need to add the formated post into the db with the same id as the unformatted post, and we want to keep both posts. This, of course, causes plenty of problems for other things ... such as the front page post list. This could probably all be solved with a GROUP BY (id) clause, so I will investigate everything that could possibly break.

Changed 2 years ago by latiass

Oh. I fucked. The above only works with one HTML-ized post and breaks with further. The following ..

    my @htmlized =  map { $_->id } $c->model('DBIC::Posts')->search({ 'me.format' => 'html' }); # find posts that are HTMLized
    my $posts_rs = $c->model('DBIC::Posts')->search({
        -and => [ 'me.threadid' => $id, ( $filter_user ? ( 'me.userid' => $filter_user->id ) : () ),
            ( @htmlized ? ( -or => [
                    { 'me.id' => [ @htmlized ], 'me.format' => 'html' },
                    { 'me.id' => [ -and => map { {'!=', $_ } } @htmlized ], 'me.format' => 'bbcode' }
                ],) : () )  
            ],
        },
        { prefetch => [ 'user', { 'lastedit', 'user' } ], order_by => 'me.time ASC', offset => $skip, rows => $perpage + 1 }
    );

... seems to work. However, there is a roadblock: I am unsure if this takes less resources than just parsing the bbcode, as that is a pretty large query and will get larger the more posts you have. There is surely an easier way to do this, but I just am not seeing it. As usual, I am probably over complicating things. ab time!

Changed 2 years ago by latiass

Although that huge mess of a query is neat in practice, and although it is slightly faster than doing nothing, trying to do everything without adding another column breaks more things than it helps fix. In favor of this, I have simply added a column called 'content', which is a parsed message. Much easier, and under heavy bbcode situations, proves to be twice as fast. Will commit when I am done fiddling with it.

Add/Change #200 (Caching of parsed posts)

Author


E-mail address and user name can be saved in the Preferences.


Action
as new
 
Note: See TracTickets for help on using tickets.