The SQL statement in chatroom.install calls for the chatroom_msg.msg field to be longtext. This is not good. It wastes space and makes MySQL perform worse. Since chat messages are hardly ever in the vicinity of 4,294,967,296 bytes long, wouldn't it make more sense to speed the db up by defining that column as varchar(255), or, if you really need more, TEXT(512)?

      $ok = $ok && db_query("CREATE TABLE {chatroom_msg} (
        cmid int(11) NOT NULL AUTO_INCREMENT,
        ccid int(11) NOT NULL,
        uid int(11) NOT NULL,
        msg_type varchar(64) NOT NULL,
/*        msg longtext NOT NULL,*/
		msg text(512) NOT NULL,
        session_id varchar(255) NOT NULL,
        recipient varchar(255) NOT NULL,
        modified int(11) NOT NULL default '0',
        PRIMARY KEY  (cmid),
        KEY ccid (ccid),
        KEY session_id (session_id),
        KEY recipient (recipient),
        KEY modified (modified)
      ) $utf_declaration;");
      $ok = $ok && db_query("CREATE TABLE {chatroom_msg_archive} (

Comments

darren oh’s picture

Status: Active » Needs review
StatusFileSize
new1.01 KB
apotek’s picture

My bad: I just remembered that TEXT(512) won't work, but VARCHAR(512) will. Text doesn't seem to respect any length indicator. So I would make the patch say VARCHAR(512).

I have tested with this change, and the appliation quite gracefully just truncates submitted text. However, maybe we ought to think of a way to use an alert message when someone submits a string longer than n characters.

But this is a good start. Will definitely improve performance.

apotek’s picture

StatusFileSize
new1.01 KB

Here's the modified patch for setting the msg column to varchar(512).

darren oh’s picture

Version: 4.7.x-1.x-dev » 5.x-1.x-dev
Assigned: Unassigned » darren oh
Category: bug » task
Status: Needs review » Fixed

Fixed in CVS commit 71985. I limited the number of characters that users can enter into the text field to 128 to prevent messages from being truncated.

Anonymous’s picture

Status: Fixed » Closed (fixed)