What is the xf_attachment_view table for?

emc2

Active member
Like the title asks, what is the purpose of the attachment view table??

I have looked at the code but couldn't work it out
 
Logs the viewing of an attachment.
PHP:
/**
    * Logs the viewing of an attachment.
    *
    * @param integer $attachmentId
    */
    public function logAttachmentView($attachmentId)
    {
        $this->_getDb()->query('
            INSERT ' . (XenForo_Application::get('options')->enableInsertDelayed ? 'DELAYED' : '') . ' INTO xf_attachment_view
                (attachment_id)
            VALUES
                (?)
        ', $attachmentId);
    }
 
It's a MySQL memory table. Each time someone views an attachment it logs the attachment ID in there.

Later on, a Cron entry will add those to the view_count in the xf_attachment table.
 
Oh I c.

I understood the 'Logs the viewing of an attachment.' but couldn't figure out why.. Very smart way to do it in regards to performance..
 
The technique has been around for ages, maybe as old as vBulletin 2
But then, part of the reason was an update locked the full MyISAM table. These days, InnoDB has row locking, so I am not really sure how terribly necessary this is anymore.
 
I would prefer to have it log the user_id and date.

Thanks for the explanation, I was also curious :)
 
There's no point in it logging the user_id and date as the table is truncated via a cron periodically and the process that does that would only grab the number of times its been viewed and update the view_count column.

Alhough what you're suggesting would be more functional, you wouldn't be able to make that fit in the current process... You'd have to create your own, additional table and modify the log attachment view function to still write to the existing table, but then additionally write to your custom table the other details you want.
 
The technique has been around for ages, maybe as old as vBulletin 2
But then, part of the reason was an update locked the full MyISAM table. These days, InnoDB has row locking, so I am not really sure how terribly necessary this is anymore.

It's still a good bit more efficient to do it this way
 
Back
Top Bottom