summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp77
-rw-r--r--gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h5
-rw-r--r--gentoobrowse-api/service/sql/maintenance/ebuildInsert.sql2
-rw-r--r--gentoobrowse-api/service/sql/maintenance/ebuildUpdate.sql3
4 files changed, 69 insertions, 18 deletions
diff --git a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp
index 648decf..2b2541b 100644
--- a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp
+++ b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp
@@ -1,6 +1,8 @@
#include "ebuildMetaProcessor.h"
#include <modifycommand.h>
#include <sqlWriter.h>
+#include <selectcommandUtil.impl.h>
+#include <sqlWriter.h>
#include <boost/filesystem/operations.hpp>
#include <glibmm/regex.h>
#include <tablepatch.h>
@@ -58,25 +60,27 @@ namespace Gentoo {
class SplitEbuildProps : public DB::SqlWriter {
public:
- SplitEbuildProps(int e, const std::string & p) :
+ SplitEbuildProps(int e, const std::string & c, const boost::optional<Glib::ustring> & p) :
ebuildId(e),
+ colName(c),
props(p)
{
}
void writeSql(AdHoc::Buffer & sql) override
{
- sql.append("(SELECT ?::int ebuildId, trim(regexp_split_to_table(?, '\\s+'), '+') use)");
+ sql.appendbf("(SELECT DISTINCT ?::int ebuildId, trim(regexp_split_to_table(?, '\\s+'), '+') %s)", colName);
}
void bindParams(DB::Command * c, unsigned int & offset) override
{
c->bindParamI(offset++, ebuildId);
- c->bindParamS(offset++, props);
+ Utils::Database::bindOptionalsS(c, offset++, { props });
}
const int ebuildId;
- const std::string props;
+ const std::string colName;
+ const boost::optional<Glib::ustring> props;
};
const int EbuildMetaProcessor::FILETYPEID = 1;
@@ -106,7 +110,7 @@ namespace Gentoo {
pi->bindParamS(3, categoryName);
pi->execute();
// Create an ebuild
- auto m = dbc->modify(sql::maintenance::ebuildInsert::sql);
+ auto m = dbc->select(sql::maintenance::ebuildInsert::sql);
m->bindParamS(0, ebuildVersion);
m->bindParamS(1, ebuildVersion);
Utils::Database::bindOptionalsS(m.get(), 2, { ecp.get("SLOT") });
@@ -115,15 +119,9 @@ namespace Gentoo {
m->bindParamS(5, repoName);
m->bindParamS(6, categoryName);
m->bindParamS(7, packageName);
- m->forEachRow<int64_t>([dbc,&ecp] (auto ebuildId) {
- // USE flags
- DB::TablePatch t;
- SplitEbuildProps sep(ebuildId, ecp.get("USE").value_or(Glib::ustring()));
- t.dest = "gentoobrowse.ebuild_uses";
- t.srcExpr = &sep;
- t.pk = { "ebuildid", "use" };
- t.cols = { "ebuildid", "use" };
- dbc->patchTable(&t);
+ m->forEachRow<int64_t>([this,dbc,&ecp,&fn] (auto ebuildId) {
+ fprintf(stderr, "Created ebuild %ld for %s\n", ebuildId, fn.c_str());
+ this->perEbuildUpdates(dbc, ecp, ebuildId);
});
}
}
@@ -134,19 +132,62 @@ namespace Gentoo {
Glib::MatchInfo matches;
const Glib::ustring pv = (fn / 4).string();
if (packageVersion->match(pv, matches)) {
- auto m = dbc->modify(sql::maintenance::ebuildUpdate::sql);
+ auto m = dbc->select(sql::maintenance::ebuildUpdate::sql);
EbuildCacheParser ecp(path);
- Utils::Database::bindOptionalsS(m, 0, { ecp.get("SLOT") });
- Utils::Database::bindOptionalsS(m, 1, { ecp.get("LICENSE") });
+ Utils::Database::bindOptionalsS(m.get(), 0, { ecp.get("SLOT") });
+ Utils::Database::bindOptionalsS(m.get(), 1, { ecp.get("LICENSE") });
m->bindParamT(2, boost::posix_time::from_time_t(ecp.getStat().st_mtim.tv_sec));
m->bindParamS(3, (fn / 0).string()); // repo
m->bindParamS(4, (fn / 3).string()); // category
m->bindParamS(5, matches.fetch(1)); // package
m->bindParamS(6, matches.fetch(2)); // version
- m->execute(false);
+ m->forEachRow<int64_t>([this,dbc,&ecp,&fn] (auto ebuildId) {
+ fprintf(stderr, "Updated ebuild %ld for %s\n", ebuildId, fn.c_str());
+ this->perEbuildUpdates(dbc, ecp, ebuildId);
+ });
}
}
+ class EbuildWhereFilter : public DB::SqlWriter {
+ public:
+ EbuildWhereFilter(int64_t e) : ebuildId(e) { }
+
+ void writeSql(AdHoc::Buffer & sql) override
+ {
+ sql.append("b.ebuildId = ?");
+ }
+
+ void bindParams(DB::Command * c, unsigned int & offset) override
+ {
+ c->bindParamI(offset++, ebuildId);
+ }
+
+ const int64_t ebuildId;
+ };
+
+ void
+ EbuildMetaProcessor::perEbuildUpdates(DB::Connection * dbc, const EbuildCacheParser & ecp, int64_t ebuildId) const
+ {
+ EbuildWhereFilter ewf(ebuildId);
+ // USE flags
+ DB::TablePatch t;
+ SplitEbuildProps sep_use(ebuildId, "use", ecp.get("IUSE"));
+ t.dest = "gentoobrowse.ebuild_uses";
+ t.srcExpr = &sep_use;
+ t.pk = { "ebuildid", "use" };
+ t.cols = { "ebuildid", "use" };
+ t.where = &ewf;
+ dbc->patchTable(&t);
+ // USE flags
+ SplitEbuildProps sep_keywords(ebuildId, "arch", ecp.get("KEYWORDS"));
+ t.dest = "gentoobrowse.ebuild_archs";
+ t.srcExpr = &sep_keywords;
+ t.pk = { "ebuildid", "arch" };
+ t.cols = { "ebuildid", "arch" };
+ t.where = &ewf;
+ dbc->patchTable(&t);
+ }
+
void
EbuildMetaProcessor::deleted(DB::Connection * dbc, const boost::filesystem::path & fn) const
{
diff --git a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h
index d06ccf9..90c0d94 100644
--- a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h
+++ b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h
@@ -8,6 +8,8 @@
namespace Gentoo {
namespace Service {
+ class EbuildCacheParser;
+
class EbuildMetaProcessor : public Maintenance::FileProcessor {
public:
static const int FILETYPEID;
@@ -15,6 +17,9 @@ namespace Gentoo {
void created(DB::Connection * dbc, const boost::filesystem::path & fn, const boost::filesystem::path & path) const;
void modified(DB::Connection * dbc, const boost::filesystem::path & fn, const boost::filesystem::path & path) const;
void deleted(DB::Connection * dbc, const boost::filesystem::path & fn) const;
+
+ private:
+ void perEbuildUpdates(DB::Connection * dbc, const EbuildCacheParser & ecp, int64_t ebuildId) const;
};
}
}
diff --git a/gentoobrowse-api/service/sql/maintenance/ebuildInsert.sql b/gentoobrowse-api/service/sql/maintenance/ebuildInsert.sql
index 949b92a..110b7c8 100644
--- a/gentoobrowse-api/service/sql/maintenance/ebuildInsert.sql
+++ b/gentoobrowse-api/service/sql/maintenance/ebuildInsert.sql
@@ -1,3 +1,4 @@
+-- libdbpp:no-cursor
INSERT INTO gentoobrowse.ebuilds(packageid, version, versioninst, slot, license, moddate, repoid)
SELECT p.packageid, ?, gentoobrowse.ebuildversion_constructor(?), ?, ?, ?, r.repoid
FROM gentoobrowse.packages p, gentoobrowse.categories c, gentoobrowse.repos r
@@ -5,3 +6,4 @@ WHERE c.categoryid = p.categoryid
AND r.name = ?
AND c.name = ?
AND p.name = ?
+RETURNING ebuildid
diff --git a/gentoobrowse-api/service/sql/maintenance/ebuildUpdate.sql b/gentoobrowse-api/service/sql/maintenance/ebuildUpdate.sql
index dc8ae85..fc83417 100644
--- a/gentoobrowse-api/service/sql/maintenance/ebuildUpdate.sql
+++ b/gentoobrowse-api/service/sql/maintenance/ebuildUpdate.sql
@@ -1,10 +1,13 @@
+-- libdbpp:no-cursor
UPDATE gentoobrowse.ebuilds e SET
slot = ?,
license = ?,
moddate = ?
FROM gentoobrowse.packages p, gentoobrowse.categories c, gentoobrowse.repos r
WHERE c.categoryid = p.categoryid
+AND e.packageid = p.packageid
AND r.name = ?
AND c.name = ?
AND p.name = ?
AND e.version = ?
+RETURNING ebuildid