1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

What is the xf_attachment_view table for?

Discussion in 'XenForo Development Discussions' started by emc2, Sep 18, 2013.

  1. emc2

    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
     
    Marcus likes this.
  2. Nobita.Kun

    Nobita.Kun Well-Known Member

    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);
        }
     
    Marcus likes this.
  3. Chris D

    Chris D XenForo Developer Staff Member

    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.
     
    Marcus likes this.
  4. emc2

    emc2 Active Member

    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..
     
  5. Rigel Kentaurus

    Rigel Kentaurus Well-Known Member

    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.
     
    Marcus likes this.
  6. Marcus

    Marcus Well-Known Member

    I would prefer to have it log the user_id and date.

    Thanks for the explanation, I was also curious :)
     
  7. Chris D

    Chris D XenForo Developer Staff Member

    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.
     
  8. Luke F

    Luke F Well-Known Member

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

Share This Page