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

Using The DataWriter To Write Bulk Rows...Necessary? Possible?

Discussion in 'XenForo Development Discussions' started by mjda, Feb 19, 2015.

  1. mjda

    mjda Active Member

    I'm trying to develop a new addon for my site that will allow members to submit certain data that will contain long lists of information. Now, I've already got the addon working, with 1 exception. When they submit a list, I need each line on their list to be entered into the database.

    Right now I'm using a foreach with the datawriter process taking place for each line. Is this ok, or will something break if the list contains say 1000 lines of data? That would be 1,000 mysql entries at once, which seems like way too much to me.

    So, is there a better/more efficient way for me to add all of those rows, maybe with a single query, using the DataWriter?
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    DataWriters will only support inserting or updating a single record at a time.

    Whether they are appropriate to use, or not, depends very much on any life cycle behaviours you need attaching to the insert, e.g. if inserting a record needs to trigger something else to happen then a DataWriter is appropriate. For example, think of a post being inserted into a watched thread, an alert needs to be sent to everyone watching - that is triggered, initially, by the DataWriter.

    If nothing of that sort needs to happen on insert, then it may be ok to not use the DW for that purpose and insert the data some other way.

    You could still use the DWs for things like updates if necessary.

    It isn't uncommon for the DW to be used in a loop in some cases, but they weren't really designed with that volume in mind.
     
    Marcus and mjda like this.
  3. mjda

    mjda Active Member

    Thanks, @Chris D. I kinda figured that much, but wasn't really sure. I know how to add the data with a single query myself, I was just hoping there was a way to use the DW to do it. No big deal. Never hurts to ask!

    Thanks, again, for the info.
     
  4. tyteen4a03

    tyteen4a03 Well-Known Member

    You should probably using raw SQL here.
     

Share This Page