[addondb] adds CAddonDatabase::GetAddonVersion() to speed up repository parsing
authorJonathan Marshall <jmarshall@xbmc.org>
Sun, 26 Jan 2014 03:59:08 +0000 (16:59 +1300)
committerJonathan Marshall <jmarshall@xbmc.org>
Tue, 28 Jan 2014 08:16:57 +0000 (21:16 +1300)
xbmc/addons/AddonDatabase.cpp
xbmc/addons/AddonDatabase.h
xbmc/addons/Repository.cpp

index e803cab..524895a 100644 (file)
@@ -181,6 +181,39 @@ int CAddonDatabase::AddAddon(const AddonPtr& addon,
   return -1;
 }
 
+AddonVersion CAddonDatabase::GetAddonVersion(const std::string &id)
+{
+  AddonVersion maxversion("0.0.0");
+  try
+  {
+    if (NULL == m_pDB.get()) return maxversion;
+    if (NULL == m_pDS2.get()) return maxversion;
+
+    // there may be multiple addons with this id (eg from different repositories) in the database,
+    // so we want to retrieve the latest version.  Order by version won't work as the database
+    // won't know that 1.10 > 1.2, so grab them all and order outside
+    CStdString sql = PrepareSQL("select version from addon where addonID='%s'",id.c_str());
+    m_pDS2->query(sql.c_str());
+
+    if (m_pDS2->eof())
+      return maxversion;
+
+    while (!m_pDS2->eof())
+    {
+      AddonVersion version(m_pDS2->fv(0).get_asString());
+      if (version > maxversion)
+        maxversion = version;
+      m_pDS2->next();
+    }
+    return maxversion;
+  }
+  catch (...)
+  {
+    CLog::Log(LOGERROR, "%s failed on addon %s", __FUNCTION__, id.c_str());
+  }
+  return maxversion;
+}
+
 bool CAddonDatabase::GetAddon(const CStdString& id, AddonPtr& addon)
 {
   try
index 1b3ce6f..0901a0b 100644 (file)
@@ -35,6 +35,9 @@ public:
   bool GetAddon(const CStdString& addonID, ADDON::AddonPtr& addon);
   bool GetAddons(ADDON::VECADDONS& addons);
 
+  /*! \brief grab the (largest) add-on version for an add-on */
+  ADDON::AddonVersion GetAddonVersion(const std::string &id);
+
   /*! \brief Grab the repository from which a given addon came
    \param addonID - the id of the addon in question
    \param repo [out] - the id of the repository
index e0b4e57..e555ab4 100644 (file)
@@ -291,12 +291,8 @@ bool CRepositoryUpdateJob::DoWork()
 
     // Check if we should mark the add-on as broken.  We may have a newer version
     // of this add-on in the database or installed - if so, we keep it unbroken.
-    bool haveNewer = addon && addon->Version() > newAddon->Version();
-    if (!haveNewer)
-    {
-      AddonPtr dbAddon;
-      haveNewer = database.GetAddon(newAddon->ID(), dbAddon) && dbAddon->Version() > newAddon->Version();
-    }
+    bool haveNewer = (addon && addon->Version() > newAddon->Version()) ||
+                     database.GetAddonVersion(newAddon->ID()) > newAddon->Version();
     if (!haveNewer)
     {
       if (!newAddon->Props().broken.empty())