Operation longue

Rapakooti Messages postés 92 Date d'inscription mercredi 4 décembre 2002 Statut Membre Dernière intervention 18 mai 2018 - 1 avril 2018 à 15:31
Rapakooti Messages postés 92 Date d'inscription mercredi 4 décembre 2002 Statut Membre Dernière intervention 18 mai 2018 - 1 avril 2018 à 18:27
Bonjour,

Je ne comprend pas, je récupère une liste de film dans une listbox. Quand je clique sur une ligne de cette liste une requête va récupérer des info dans une base de donnée... tout fonctionne mais la premiere fois que je clique l'operation est beaucoup plus longue qu'apres. Avez vous une idée d'ou ca peut venir??

merci

voici l'operation

  private void listBoxfilm_SelectedIndexChanged(object sender, EventArgs e)
{
string contenurequ;
string nom;
string fichier;
string affiche="";
string fanart="";
string emplacement = "";
string extension = "";
string taille = "";
string idfilm = "";
string codec = "";


CultureInfo francais = CultureInfo.GetCultureInfo("fr-FR");
CultureInfo canadien = CultureInfo.GetCultureInfo("fr-CA");

if (listBoxfilm.SelectedItem !=null)
{
nom = listBoxfilm.SelectedItem.ToString().Replace("'", "''");

contenurequ = "SELECT b.c00, b.premiered , b.c22, a.strFilename, b.c14, a.dateAdded, c08,c20, a.idFile,c.strVideoCodec FROM files AS a, movie AS b ,streamdetails AS c WHERE (a.idFile = b.idFile) AND (b.idFile=c.idFile) AND (b.c00='" + nom + "')";

if (cn.State == ConnectionState.Open)
{
cn.Close();

}
cn.Open();

MySqlCommand requete = new MySqlCommand(contenurequ);
requete.Connection = cn;
MySqlDataReader reader = requete.ExecuteReader();
while (reader.Read())
{
fichier = reader[2].ToString() + reader[3].ToString();

fichier = fichier.Replace("smb:", "");
FileInfo fi1 = new FileInfo(fichier);

affiche = reader[6].ToString();
fanart = reader[7].ToString();
emplacement= reader[2].ToString();
extension = fi1.Extension.ToString();
taille = GetSize(fi1.Length);
idfilm= reader[8].ToString();
if (reader[9].ToString()!="")
codec = reader[9].ToString();
}
Tcodec.Text = codec;
Templacement.Text = emplacement;
Tnom.Text = reader[0].ToString();
Textension.Text = extension;
//gestion de la taille de fichier
if (File.Exists(Application.StartupPath + "/cache/" + idfilm + "affiche.jpg"))
{
Paffiche.Load(Application.StartupPath + "/cache/" + idfilm + "affiche.jpg");

}
else
{
affiche = affiche.Substring(affiche.IndexOf("=") + 2, affiche.IndexOf(">") - affiche.IndexOf("=") - 3);
Paffiche.Load(affiche);
Paffiche.Image.Save(Application.StartupPath + "/cache/" + idfilm + "affiche.jpg");
}

if (File.Exists(Application.StartupPath + "/cache/" + idfilm + "fanart.jpg"))
{
Pfan.Load(Application.StartupPath + "/cache/" + idfilm + "fanart.jpg");

}
else
{
fanart = fanart.Replace("<fanart><thumb preview=", "");
fanart = fanart.Substring(1, fanart.IndexOf(">") - 2);

Pfan.Load(fanart);
Pfan.Image.Save(Application.StartupPath + "/cache/" + idfilm + "fanart.jpg");
}


DateTime dt = DateTime.Parse(reader[5].ToString(), canadien);
Tajout.Text = dt.ToString(francais).Substring(0, 10);
Ttaille.Text = taille;

cn.Close();


Je sais que bcp de truc sont perfectible si vous avez une idéé. Par exemple la requete me renvoie deux lignes

merci

2 réponses

NHenry Messages postés 15069 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 29 mai 2023 158
1 avril 2018 à 17:50
Probablement le cache de ta BDD, regardes si tu as bien mis des indexs cohérents.
Sinon, que se passe-t-il si un nom de film contient un ' ?
0
Rapakooti Messages postés 92 Date d'inscription mercredi 4 décembre 2002 Statut Membre Dernière intervention 18 mai 2018
1 avril 2018 à 18:27
Alors déjà merci pour la réponse. Si le titre a un apostrophe ca fonctionne avec le replacement. Je pense aussi peut etre au cache mais je vois pas comment accéléré les choses... Pour les index j utilise la base de kodi. Je pense que si je modifie la requete ca ira plus vite mais j ai pas trouvé pour l instant
0