title: Update the view less often
body: <p>I developed a program in a QMainWindow, with a QTableView based on a QSqlTableModel. The database uses sqlite. </p>
  
  <p>This program is supposed to display a list of videos. I can normally add some tags and actor to each video (tags and actors are stored in the database). When I have a few videos displayed, everything works fine, but when the number of videos increases, my program raises an exception like that:</p>
  
  <pre><code>Traceback (most recent call last):
  File "/home/djipey/informatique/python/bibli/gui.py", line 572, in addTag
  liste.addTag(vids_selected, tag_to_add.split(" "))
  File "/home/djipey/informatique/python/bibli/liste.py", line 488, in addTag
  bdd.commit()
  sqlite3.OperationalError: database is locked
  </code></pre>
  
  <p>I'm almost sure the problem doesn't come from liste.py, because I close each connection and cursor. No, my database is busy somewhere else.</p>
  
  <p>I assume the problem comes from the view/model when they display the informations, so I wonder if it's possible to dicrease the display rate? Otherwise, I'm open to every suggestion to fix the problem.</p>
  
  <pre><code>def addTag(list_vids, list_tags):
  
      """ Ajoute tous les tags de list_tags à chaque vid de list_vids. Pour
  cela crée un tag dans la table tags, puis établit une relation entre
  l'id de la vidéo et l'id du tag créé. Inscrit la correspondance dans
  la table videos_tags. """
  
      bdd = sqlite3.connect("fichiers.sqlite") # ouverture de la base
      bdd.row_factory = sqlite3.Row # accès aux colonnes par leur nom, pas par leur index
  
      c = bdd.cursor() # obtention d'un curseur
  
      #On ajoute le tag transmis à la table tags s'il n'existe pas déjà
      for each_tag in list_tags:
          c.execute("SELECT * FROM tags WHERE name= ? ", (each_tag,))
          if c.fetchone() is None:
              c.execute("INSERT INTO tags (name) VALUES (?) ", (each_tag,))
  
              bdd.commit()
  
      for each_video in list_vids:
          for each_tag in list_tags:
              #On récupère l'id du tag pour s'en servir après
              c.execute("SELECT id FROM tags WHERE name= ?", (each_tag,))
              id_tag_recupere = c.fetchone()["id"]
  
              #On vérifie que le tag à stocker n'est pas déjà associé à la vidéo 
              c.execute("SELECT * FROM videos_tags WHERE id_video = ? AND id_tag = ?", (each_video, id_tag_recupere))
              if c.fetchone() is None:
                  c.execute("INSERT INTO videos_tags (id_video, id_tag) VALUES (?, ?)", (each_video, id_tag_recupere))
                  bdd.commit()
              else:
                  print("Cette vidéo a déjà ce tag")
  
      c.close()
  </code></pre>