Loading ...
Sorry, an error occurred while loading the content.

482Speed up insertion without duplicates?

Expand Messages
  • markuswaltre
    Mar 24, 2014
    • 0 Attachment
      I have the following code:

              var db_message = TAFFY();
                var timestamp = $(messages[n]).find('span.meta')[0].innerHTML;
                var date = databaseTime(timestamp);
                var db_pos = db_message({date:date}).first();
                if(db_pos.date != undefined) {
                  // increment
                } else {
                  // add record
                  db_message.insert({date: date, count: 1});

      It basically just adds a date record into the database but checks for existing dates and in that case increments the count. I'm wondering if there is a smarter way to go about this? As of now I have that n is about 85000. And that takes about 9-12 seconds for the function to run based on console.time. Also is there any risk for this database get close to 5MB? The database will not hold more than 4000 unique records.