From e1f325f8fa80a077d41cc2874ebdba589a7512f2 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 25 Jan 2015 18:47:47 +0000 Subject: Return the select columns from CreateColumns and pass it back into BindColumns (saves repeated metadata lookups) --- p2pvr/daemon/maintenance/events.cpp | 16 ++++++++++------ p2pvr/daemon/maintenance/network.cpp | 16 ++++++++-------- p2pvr/daemon/maintenance/services.cpp | 4 ++-- p2pvr/daemon/schedules.cpp | 9 +++++---- p2pvr/lib/containerIterator.h | 4 ++-- p2pvr/lib/objectRowState.cpp | 17 ++++++++++------- p2pvr/lib/objectRowState.h | 13 +++++++------ 7 files changed, 44 insertions(+), 35 deletions(-) diff --git a/p2pvr/daemon/maintenance/events.cpp b/p2pvr/daemon/maintenance/events.cpp index 92b214c..8c0834b 100644 --- a/p2pvr/daemon/maintenance/events.cpp +++ b/p2pvr/daemon/maintenance/events.cpp @@ -13,29 +13,32 @@ ResourceString(Maint_pruneEvents, sql_Maint_pruneEvents); class SiEventsHandler : public SiEpgParser { public: - SiEventsHandler(const RowProcessorCallback & cb) : + SiEventsHandler(const RowProcessorCallback & cb, const SelectedColumns & sc) : + ecs(sc), callBack(cb) {} bool HandleTable(DVBSI::EventPtr e) { Logger()->messagebf(LOG_DEBUG, "Service Id: %d Program Id: %d Title: %s Time: %s - %s", e->ServiceId, e->EventId, e->Title, e->StartTime, e->StopTime); - BindColumns(rowState, e); + BindColumns(rowState, ecs, e); rowState.process(callBack); return false; } private: ObjectRowState rowState; + const SelectedColumns & ecs; const RowProcessorCallback callBack; }; class SiEventsMerger : public IHaveSubTasks { public: - SiEventsMerger(short t, const Ice::Current & i) : + SiEventsMerger(short t, const Ice::Current & i, const SelectedColumns & sc) : SourceObject(__PRETTY_FUNCTION__), IHaveSubTasks(NULL), type(t), + ecs(sc), ice(i) { } void execute(ExecContext * ec) const @@ -49,7 +52,7 @@ class SiEventsMerger : public IHaveSubTasks { } TemporarayIceAdapterObject parser(ice.adapter, - new SiEventsHandler(boost::bind(&SiEventsMerger::executeChildren, this, ec))); + new SiEventsHandler(boost::bind(&SiEventsMerger::executeChildren, this, ec), ecs)); auto delivery = si->GetDeliveryForSi(); if (!delivery) { @@ -65,6 +68,7 @@ class SiEventsMerger : public IHaveSubTasks { private: const short type; + const SelectedColumns & ecs; const Ice::Current & ice; void executeChildren(ExecContext * ec) const @@ -80,8 +84,8 @@ Maintenance::UpdateEvents(short type, const Ice::Current & ice) { TxHelper tx(this); SqlMergeTask mergeEvents("postgres", "events"); - CreateColumns(boost::bind(SqlMergeColumnsInserter, &mergeEvents, _1, _2)); - mergeEvents.sources.insert(new SiEventsMerger(type, ice)); + auto ecs = CreateColumns(boost::bind(SqlMergeColumnsInserter, &mergeEvents, _1, _2)); + mergeEvents.sources.insert(new SiEventsMerger(type, ice, ecs)); mergeEvents.insteadOfDelete = new DynamicSql::SqlText("SET current = false"); mergeEvents.updateWhere = new DynamicSql::SqlText("a.current"); mergeEvents.loadComplete(this); diff --git a/p2pvr/daemon/maintenance/network.cpp b/p2pvr/daemon/maintenance/network.cpp index 3c21639..97598ad 100644 --- a/p2pvr/daemon/maintenance/network.cpp +++ b/p2pvr/daemon/maintenance/network.cpp @@ -26,15 +26,15 @@ class SiNetworkInformationMerger : public SiNetworkInformationParser { DatabaseClient::TxHelper tx(commonObjects); SqlMergeTask mergeNetwork("postgres", "networks"); - CreateColumns(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeNetwork, _1, _2)); + auto ncs = CreateColumns(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeNetwork, _1, _2)); std::vector networks = { n }; - mergeNetwork.sources.insert(new ContainerIterator>(&networks)); + mergeNetwork.sources.insert(new ContainerIterator>(&networks, ncs)); mergeNetwork.loadComplete(commonObjects); mergeNetwork.execute(NULL); SqlMergeTask mergeTransports("postgres", "transportstreams"); - CreateColumns(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeTransports, _1, _2)); - mergeTransports.sources.insert(new ContainerIterator(&n->TransportStreams)); + auto tscs = CreateColumns(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeTransports, _1, _2)); + mergeTransports.sources.insert(new ContainerIterator(&n->TransportStreams, tscs)); mergeTransports.loadComplete(commonObjects); mergeTransports.execute(NULL); @@ -43,9 +43,9 @@ class SiNetworkInformationMerger : public SiNetworkInformationParser { mergeDelivery("delivery_dvbc", n); SqlMergeTask mergeServices("postgres", "services"); - CreateColumns(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeServices, _1, _2)); + auto scs = CreateColumns(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeServices, _1, _2)); for (const auto & s : n->TransportStreams) { - mergeServices.sources.insert(new ContainerIterator(&s->Services)); + mergeServices.sources.insert(new ContainerIterator(&s->Services, scs)); } mergeServices.loadComplete(commonObjects); mergeServices.execute(NULL); @@ -56,14 +56,14 @@ class SiNetworkInformationMerger : public SiNetworkInformationParser { void mergeDelivery(const std::string & table, DVBSI::NetworkPtr n) { SqlMergeTask merge("postgres", table); - CreateColumns(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &merge, _1, _2)); + auto dcs = CreateColumns(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &merge, _1, _2)); std::vector dels; for (const auto & s : n->TransportStreams) { if (auto d = s.get()->*member) { dels.push_back(d); } } - merge.sources.insert(new ContainerIterator(&dels)); + merge.sources.insert(new ContainerIterator(&dels, dcs)); merge.loadComplete(commonObjects); merge.execute(NULL); } diff --git a/p2pvr/daemon/maintenance/services.cpp b/p2pvr/daemon/maintenance/services.cpp index 50056ff..afa8084 100644 --- a/p2pvr/daemon/maintenance/services.cpp +++ b/p2pvr/daemon/maintenance/services.cpp @@ -23,11 +23,11 @@ class SiServicesMerger : public SiServicesParser { DatabaseClient::TxHelper tx(commonObjects); SqlMergeTask mergeServices("postgres", "services"); - CreateColumns(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeServices, _1, _2)); + auto scs = CreateColumns(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeServices, _1, _2)); // Don't change the list of services available from the network mergeServices.doDelete = VariableType(false); mergeServices.doInsert = VariableType(false); - mergeServices.sources.insert(new ContainerIterator(&ts->Services)); + mergeServices.sources.insert(new ContainerIterator(&ts->Services, scs)); mergeServices.loadComplete(commonObjects); mergeServices.execute(NULL); return false; diff --git a/p2pvr/daemon/schedules.cpp b/p2pvr/daemon/schedules.cpp index 4ced9a7..5b0b5cd 100644 --- a/p2pvr/daemon/schedules.cpp +++ b/p2pvr/daemon/schedules.cpp @@ -54,17 +54,18 @@ typedef boost::shared_ptr RecordPtr; typedef std::vector Records; template<> -void +SelectedColumns CreateColumns(const ColumnCreator & cc) { cc("eventuid", true); cc("recordstatus", false); cc("scheduleid", false); + return {true, true, true}; } template<> void -BindColumns(RowState & rs, RecordPtr const & s) +BindColumns(RowState & rs, const SelectedColumns &, RecordPtr const & s) { rs.fields[0] << s->EventUid; rs.fields[1] << (int)s->RecordStatus; @@ -325,8 +326,8 @@ Schedules::DoReschedule(const Ice::Current & ice) TxHelper tx(this); SqlMergeTask mergeRecords("postgres", "record"); - CreateColumns(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeRecords, _1, _2)); - mergeRecords.sources.insert(new ContainerIterator(&records)); + auto rcs = CreateColumns(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeRecords, _1, _2)); + mergeRecords.sources.insert(new ContainerIterator(&records, rcs)); mergeRecords.loadComplete(this); mergeRecords.execute(NULL); tx.Commit(); diff --git a/p2pvr/lib/containerIterator.h b/p2pvr/lib/containerIterator.h index 03af88c..dac2639 100644 --- a/p2pvr/lib/containerIterator.h +++ b/p2pvr/lib/containerIterator.h @@ -7,10 +7,10 @@ template class ContainerIterator : public IHaveSubTasks { public: - ContainerIterator(const T * con) : + ContainerIterator(const T * con, const SelectedColumns & sc) : SourceObject(__PRETTY_FUNCTION__), IHaveSubTasks(NULL), - binder(boost::bind(&BindColumns, _1, _2)), + binder(boost::bind(&BindColumns, _1, sc, _2)), container(con) { } diff --git a/p2pvr/lib/objectRowState.cpp b/p2pvr/lib/objectRowState.cpp index c882405..3f04cda 100644 --- a/p2pvr/lib/objectRowState.cpp +++ b/p2pvr/lib/objectRowState.cpp @@ -10,14 +10,18 @@ mdHasFlag(const std::list & md, const std::string & flag) return std::find(md.begin(), md.end(), flag) != md.end(); } -void +SelectedColumns CreateColumns(Slicer::ModelPartPtr mp, const ColumnCreator & cc) { - mp->OnEachChild([cc](const std::string & name, Slicer::ModelPartPtr, Slicer::HookCommonPtr h) { + SelectedColumns cols; + mp->OnEachChild([cc,&cols](const std::string & name, Slicer::ModelPartPtr, Slicer::HookCommonPtr h) { auto & md = h->GetMetadata(); - if (mdHasFlag(md, md_mergeOmit)) return; + auto omitted = mdHasFlag(md, md_mergeOmit); + cols.push_back(!omitted); + if (omitted) return; cc(name, mdHasFlag(md, md_mergeKey)); }); + return cols; } class SqlTarget : public Slicer::ValueTarget, @@ -45,12 +49,11 @@ class SqlTarget : public Slicer::ValueTarget, typedef IceUtil::Handle SqlTargetPtr; void -BindColumns(Slicer::ModelPartPtr mp, RowState & rs) +BindColumns(Slicer::ModelPartPtr mp, const SelectedColumns & sc, RowState & rs) { unsigned int field = 0; - mp->OnEachChild([&rs,&field](const std::string &, Slicer::ModelPartPtr mp, Slicer::HookCommonPtr h) { - auto & md = h->GetMetadata(); - if (mdHasFlag(md, md_mergeOmit)) return; + mp->OnEachChild([&rs,&field,&sc](const std::string &, Slicer::ModelPartPtr mp, Slicer::HookCommonPtr) { + if (!sc[field]) return; if (mp && mp->HasValue()) { SqlTargetPtr st = new SqlTarget(rs.fields[field++]); mp->GetValue(st); diff --git a/p2pvr/lib/objectRowState.h b/p2pvr/lib/objectRowState.h index d98380b..142e5cb 100644 --- a/p2pvr/lib/objectRowState.h +++ b/p2pvr/lib/objectRowState.h @@ -8,22 +8,23 @@ typedef boost::function ColumnCreator; typedef boost::function ColumnSpecifier; +typedef std::vector SelectedColumns; -void BindColumns(Slicer::ModelPartPtr, RowState &); +void BindColumns(Slicer::ModelPartPtr, const SelectedColumns &, RowState &); template -void BindColumns(RowState & rs, const V & v) +void BindColumns(RowState & rs, const SelectedColumns & sc, const V & v) { - BindColumns(Slicer::ModelPartFor(const_cast(v)), rs); + BindColumns(Slicer::ModelPartFor(const_cast(v)), sc, rs); } -void CreateColumns(Slicer::ModelPartPtr, const ColumnCreator &); +SelectedColumns CreateColumns(Slicer::ModelPartPtr, const ColumnCreator &); template -void CreateColumns(const ColumnCreator & cc) +SelectedColumns CreateColumns(const ColumnCreator & cc) { V v; - CreateColumns(Slicer::ModelPartFor(v), cc); + return CreateColumns(Slicer::ModelPartFor(v), cc); } template -- cgit v1.2.3