Thread title cache not updated after editing a thread

1 Replies 8 Views Bug
·
Participants
Thread Starter #0
I found a small issue with thread title editing in RaxBoard:

When a thread title is changed, the title in the threads table is updated correctly, but the cached title in the forums table is not updated.

The forum/homepage listing uses:

forums.last_thread_id
forums.last_thread_title

Because of this, after editing a thread title, the thread itself shows the new title while the forum listing can still show the old title.

Fix

File:

forum/src/App/Infrastructure/Database/ThreadRepository.php

1. Replace updateTitle()


Find:

public function updateTitle(int $threadId, string $title): void { $this->db->execute( 'UPDATE threads SET title = ? WHERE id = ?', [$title, $threadId] ); }

Replace it with:

public function updateTitle(int $threadId, string $title): void { $this->db->execute( 'UPDATE threads SET title = ? WHERE id = ?', [$title, $threadId] ); $this->db->execute( 'UPDATE forums SET last_thread_title = ? WHERE last_thread_id = ?', [$title, $threadId] ); }

2. Replace updateThread()

Find:


public function updateThread(int $threadId, string $title, bool $sticky, bool $open, string $discussionState): void { $this->db->execute( 'UPDATE threads SET title = ?, sticky = ?, discussion_open = ?, discussion_state = ? WHERE id = ?', [$title, $sticky ? 1 : 0, $open ? 1 : 0, $discussionState, $threadId] ); }

Replace it with:


public function updateThread(int $threadId, string $title, bool $sticky, bool $open, string $discussionState): void { $this->db->execute( 'UPDATE threads SET title = ?, sticky = ?, discussion_open = ?, discussion_state = ? WHERE id = ?', [$title, $sticky ? 1 : 0, $open ? 1 : 0, $discussionState, $threadId] ); $this->db->execute( 'UPDATE forums SET last_thread_title = ? WHERE last_thread_id = ?', [$title, $threadId] ); }

Repair existing stale titles:
For installations that already have stale cached titles, run this SQL once:


UPDATE forums f JOIN threads t ON t.id = f.last_thread_id SET f.last_thread_title = t.title WHERE f.last_thread_id > 0;


I tested this against my installation and it correctly synchronised the old homepage title with the current thread title.

This keeps forums.last_thread_title synchronised whenever threads.title changes and prevents the homepage/forum listing from displaying an outdated thread title.

Would be great if this fix could be implemented in the upcomfing update!

Thanks!
#1
peterdevries said:
I found a small issue with thread title editing in RaxBoard:

When a thread title is changed, the title in the threads table is updated correctly, but the cached title in the forums table is not updated.

The forum/homepage listing uses:

forums.last_thread_id
forums.last_thread_title

Because of this, after editing a thread title, the thread itself shows the new title while the forum listing can still show the old title.

Fix

File:

forum/src/App/Infrastructure/Database/ThreadRepository.php

1. Replace updateTitle()


Find:

public function updateTitle(int $threadId, string $title): void { $this->db->execute( 'UPDATE threads SET title = ? WHERE id = ?', [$title, $threadId] ); }

Replace it with:

public function updateTitle(int $threadId, string $title): void { $this->db->execute( 'UPDATE threads SET title = ? WHERE id = ?', [$title, $threadId] ); $this->db->execute( 'UPDATE forums SET last_thread_title = ? WHERE last_thread_id = ?', [$title, $threadId] ); }

2. Replace updateThread()

Find:


public function updateThread(int $threadId, string $title, bool $sticky, bool $open, string $discussionState): void { $this->db->execute( 'UPDATE threads SET title = ?, sticky = ?, discussion_open = ?, discussion_state = ? WHERE id = ?', [$title, $sticky ? 1 : 0, $open ? 1 : 0, $discussionState, $threadId] ); }

Replace it with:


public function updateThread(int $threadId, string $title, bool $sticky, bool $open, string $discussionState): void { $this->db->execute( 'UPDATE threads SET title = ?, sticky = ?, discussion_open = ?, discussion_state = ? WHERE id = ?', [$title, $sticky ? 1 : 0, $open ? 1 : 0, $discussionState, $threadId] ); $this->db->execute( 'UPDATE forums SET last_thread_title = ? WHERE last_thread_id = ?', [$title, $threadId] ); }

Repair existing stale titles:
For installations that already have stale cached titles, run this SQL once:


UPDATE forums f JOIN threads t ON t.id = f.last_thread_id SET f.last_thread_title = t.title WHERE f.last_thread_id > 0;


I tested this against my installation and it correctly synchronised the old homepage title with the current thread title.

This keeps forums.last_thread_title synchronised whenever threads.title changes and prevents the homepage/forum listing from displaying an outdated thread title.

Would be great if this fix could be implemented in the upcomfing update!

Thanks!


Thank you for your feedback. This issue will be fixed in version 1.8.0.

You must be logged in to reply.

0 quotes selected