spatie / activitylog

A very simple activity logger to monitor the users of your website or application
https://spatie.be/opensource/laravel
MIT License
582 stars 75 forks source link

Batch inserts #5

Closed philipmclifton closed 9 years ago

philipmclifton commented 9 years ago

Hi, Nice work, everything works perfectly.

One suggestion.

Instead of creating an entry on every event and ramping up the database calls why not store all the events in an array and running a batch insert at the end of the request with the __destruct method?

On normal request this isn't an issue but if looping through data and creating entries the query count is 2x.

Something like this might work?

https://github.com/philipmclifton/activitylog

philipmclifton commented 9 years ago

Please note: My version might not work. need to look into it again.

freekmurze commented 9 years ago

Hi,

thanks for your suggestion.

i'm not a big fan of destructors. If somewhere during the request an error occurs nothing will get logged. This could also give some problems when running a long running script on the command line.

In most cases there will only be one or two activities that will be logged per request anyway, so I don't think the current method of logging poses a performance problem.