summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2025-01-17 02:07:01 +0100
committerCarl Hetherington <cth@carlh.net>2025-01-22 14:34:25 +0100
commit07b608ab6b2daa5f4cb366716e3aa6ece8a74f39 (patch)
tree5b7a91c6a1d5d2ff0dc132709f9fb9246f03bf33
parentefdc2359ff10ec8baf377704ef7f698aaef1ff0f (diff)
Only read screen certificates when we need them.
-rw-r--r--src/lib/cinema_list.cc36
-rw-r--r--src/lib/cinema_list.h8
-rw-r--r--src/wx/screens_panel.cc2
3 files changed, 26 insertions, 20 deletions
diff --git a/src/lib/cinema_list.cc b/src/lib/cinema_list.cc
index ffa11a36c..e4095f1c4 100644
--- a/src/lib/cinema_list.cc
+++ b/src/lib/cinema_list.cc
@@ -330,25 +330,27 @@ CinemaList::add_screen(CinemaID cinema_id, dcpomatic::Screen const& screen)
dcpomatic::Screen
-CinemaList::screen_from_result(SQLiteStatement& statement, ScreenID screen_id) const
+CinemaList::screen_from_result(SQLiteStatement& statement, ScreenID screen_id, bool with_trusted_devices) const
{
auto certificate_string = statement.column_text(4);
optional<string> certificate = certificate_string.empty() ? optional<string>() : certificate_string;
auto recipient_file_string = statement.column_text(5);
optional<string> recipient_file = recipient_file_string.empty() ? optional<string>() : recipient_file_string;
- SQLiteStatement trusted_devices_statement(_db, _trusted_devices.select("WHERE screen=?"));
- trusted_devices_statement.bind_int64(1, screen_id.get());
vector<TrustedDevice> trusted_devices;
- trusted_devices_statement.execute([&trusted_devices](SQLiteStatement& statement) {
- DCPOMATIC_ASSERT(statement.data_count() == 1);
- auto description = statement.column_text(1);
- if (boost::algorithm::starts_with(description, "-----BEGIN CERTIFICATE")) {
- trusted_devices.push_back(TrustedDevice(dcp::Certificate(description)));
- } else {
- trusted_devices.push_back(TrustedDevice(description));
- }
- });
+ if (with_trusted_devices) {
+ SQLiteStatement trusted_devices_statement(_db, _trusted_devices.select("WHERE screen=?"));
+ trusted_devices_statement.bind_int64(1, screen_id.get());
+ trusted_devices_statement.execute([&trusted_devices](SQLiteStatement& statement) {
+ DCPOMATIC_ASSERT(statement.data_count() == 3);
+ auto description = statement.column_text(2);
+ if (boost::algorithm::starts_with(description, "-----BEGIN CERTIFICATE")) {
+ trusted_devices.push_back(TrustedDevice(dcp::Certificate(description)));
+ } else {
+ trusted_devices.push_back(TrustedDevice(description));
+ }
+ });
+ }
return dcpomatic::Screen(statement.column_text(2), statement.column_text(3), certificate, recipient_file, trusted_devices);
}
@@ -364,7 +366,7 @@ CinemaList::screen(ScreenID screen_id) const
statement.execute([this, &output, screen_id](SQLiteStatement& statement) {
DCPOMATIC_ASSERT(statement.data_count() == 6);
- output = screen_from_result(statement, screen_id);
+ output = screen_from_result(statement, screen_id, true);
});
return output;
@@ -380,7 +382,7 @@ CinemaList::screens_from_result(SQLiteStatement& statement) const
statement.execute([this, &output](SQLiteStatement& statement) {
DCPOMATIC_ASSERT(statement.data_count() == 6);
ScreenID const screen_id = statement.column_int64(0);
- output.push_back({screen_id, screen_from_result(statement, screen_id)});
+ output.push_back({screen_id, screen_from_result(statement, screen_id, true)});
});
return output;
@@ -483,12 +485,12 @@ CinemaList::unique_utc_offset(std::set<CinemaID> const& cinemas_to_check)
void
-CinemaList::screens(function<void (CinemaID, ScreenID, dcpomatic::Screen const& screen)> callback) const
+CinemaList::screens(function<void (CinemaID, ScreenID, dcpomatic::Screen const& screen)> callback, bool with_trusted_devices) const
{
SQLiteStatement statement(_db, _screens.select(""));
- statement.execute([this, &callback](SQLiteStatement& statement) {
+ statement.execute([this, &callback, with_trusted_devices](SQLiteStatement& statement) {
auto const screen_id = statement.column_int64(0);
- callback(statement.column_int64(1), screen_id, screen_from_result(statement, screen_id));
+ callback(statement.column_int64(1), screen_id, screen_from_result(statement, screen_id, with_trusted_devices));
});
}
diff --git a/src/lib/cinema_list.h b/src/lib/cinema_list.h
index 6c1e65017..1e0144f73 100644
--- a/src/lib/cinema_list.h
+++ b/src/lib/cinema_list.h
@@ -105,12 +105,16 @@ public:
std::vector<std::pair<ScreenID, dcpomatic::Screen>> screens(CinemaID cinema_id) const;
std::vector<std::pair<ScreenID, dcpomatic::Screen>> screens_by_cinema_and_name(CinemaID id, std::string const& name) const;
- void screens(std::function<void (CinemaID, ScreenID, dcpomatic::Screen const&)> callback) const;
+ /** Call a callback with every screen.
+ * @param with_trusted_devices true to read screen's trusted devices into the Screen, false to not bother.
+ */
+ void screens(std::function<void (CinemaID, ScreenID, dcpomatic::Screen const&)> callback, bool with_trusted_devices) const;
boost::optional<dcp::UTCOffset> unique_utc_offset(std::set<CinemaID> const& cinemas);
private:
- dcpomatic::Screen screen_from_result(SQLiteStatement& statement, ScreenID screen_id) const;
+ /** @param with_trusted_devices true to read screen's trusted devices into the Screen, false to not bother */
+ dcpomatic::Screen screen_from_result(SQLiteStatement& statement, ScreenID screen_id, bool with_trusted_devices) const;
std::vector<std::pair<ScreenID, dcpomatic::Screen>> screens_from_result(SQLiteStatement& statement) const;
void setup_tables();
void setup(boost::filesystem::path db_file);
diff --git a/src/wx/screens_panel.cc b/src/wx/screens_panel.cc
index 6de1d86f0..d1b9280d7 100644
--- a/src/wx/screens_panel.cc
+++ b/src/wx/screens_panel.cc
@@ -534,7 +534,7 @@ ScreensPanel::add_cinemas ()
_cinema_list.screens([this](CinemaID cinema_id, ScreenID screen_id, Screen const& screen) {
add_screen(cinema_id, screen_id, screen);
- });
+ }, false);
}