Only read screen certificates when we need them.
authorCarl Hetherington <cth@carlh.net>
Fri, 17 Jan 2025 01:07:01 +0000 (02:07 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 22 Jan 2025 13:34:25 +0000 (14:34 +0100)
src/lib/cinema_list.cc
src/lib/cinema_list.h
src/wx/screens_panel.cc

index ffa11a36c807102546195daed19ec66814311d1e..e4095f1c4eb08b13540159db9abbfb6600a2049f 100644 (file)
@@ -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));
        });
 
 }
index 6c1e6501783985015c64c51f599e1a590dd6b1f0..1e0144f73320e18801792959086b7a3a0c2cee9b 100644 (file)
@@ -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);
index 6de1d86f0f6c0d5e75c59493ca0e608f53b13ad6..d1b9280d7783b90e021d5ebf73fca3b2addc5913 100644 (file)
@@ -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);
 }