mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-29 17:32:17 -07:00
[Card Database] Improve loading times through binary cache
Took 10 minutes Took 9 minutes Took 16 seconds
This commit is contained in:
parent
688c5d2a12
commit
1057d2eb3b
30 changed files with 1434 additions and 90 deletions
|
|
@ -4,6 +4,7 @@
|
|||
#include <QBasicMutex>
|
||||
#include <QList>
|
||||
#include <QLoggingCategory>
|
||||
#include <libcockatrice/card/database/card_database_data.h>
|
||||
#include <libcockatrice/interfaces/interface_card_database_path_provider.h>
|
||||
#include <libcockatrice/interfaces/interface_card_preference_provider.h>
|
||||
#include <libcockatrice/interfaces/interface_card_set_priority_controller.h>
|
||||
|
|
@ -62,16 +63,20 @@ public:
|
|||
public slots:
|
||||
/**
|
||||
* @brief Loads all configured card databases.
|
||||
*
|
||||
* The heavy work runs on a dedicated high-priority thread so it is not
|
||||
* starved by the GUI thread's startup work on low-core machines.
|
||||
* @return Status of the main database load.
|
||||
*/
|
||||
LoadStatus loadCardDatabases();
|
||||
|
||||
/**
|
||||
* @brief Loads a single card database file.
|
||||
* @brief Loads a single card database file into the given snapshot.
|
||||
* @param path Path to the database file.
|
||||
* @param data Snapshot to populate.
|
||||
* @return LoadStatus indicating success or failure.
|
||||
*/
|
||||
LoadStatus loadCardDatabase(const QString &path);
|
||||
LoadStatus loadCardDatabase(const QString &path, CardDatabaseData &data);
|
||||
|
||||
/**
|
||||
* @brief Saves custom tokens to the user-defined custom database path.
|
||||
|
|
@ -89,6 +94,12 @@ signals:
|
|||
/** @brief Emitted when loading fails. */
|
||||
void loadingFailed();
|
||||
|
||||
/**
|
||||
* @brief Emitted with the fully-built snapshot once background loading
|
||||
* completes. The receiver swaps it into the live database.
|
||||
*/
|
||||
void databaseDataReady(CardDatabaseData data);
|
||||
|
||||
/**
|
||||
* @brief Emitted when new sets are discovered during loading.
|
||||
* @param numSets Number of new sets.
|
||||
|
|
@ -101,11 +112,18 @@ signals:
|
|||
|
||||
private:
|
||||
/**
|
||||
* @brief Loads a database from a single file using the available parsers.
|
||||
* @brief Parses a single file into the given snapshot using the available parsers.
|
||||
* @param fileName Path to the database file.
|
||||
* @param data Snapshot to populate.
|
||||
* @return LoadStatus indicating success or failure.
|
||||
*/
|
||||
LoadStatus loadFromFile(const QString &fileName);
|
||||
LoadStatus loadFromFile(const QString &fileName, CardDatabaseData &data);
|
||||
|
||||
/**
|
||||
* @brief Performs the actual load work on the dedicated loader thread.
|
||||
* @return Status of the main database load.
|
||||
*/
|
||||
LoadStatus doLoadCardDatabases();
|
||||
|
||||
/**
|
||||
* @brief Collects custom card database paths recursively.
|
||||
|
|
@ -113,10 +131,36 @@ private:
|
|||
*/
|
||||
[[nodiscard]] QStringList collectCustomDatabasePaths() const;
|
||||
|
||||
/**
|
||||
* @brief Computes a hash identifying the current set of input database files.
|
||||
* @return Hash over the paths, sizes and modification times of all inputs.
|
||||
*/
|
||||
[[nodiscard]] QByteArray computeSourceHash() const;
|
||||
|
||||
/**
|
||||
* @brief Path of the binary cache file derived from the main card database path.
|
||||
* @return Cache file path.
|
||||
*/
|
||||
[[nodiscard]] QString cachePath() const;
|
||||
|
||||
/**
|
||||
* @brief Attempts to populate the snapshot from the binary cache.
|
||||
* @param data Snapshot to populate.
|
||||
* @return True if a valid, up-to-date cache was read.
|
||||
*/
|
||||
bool loadFromCache(CardDatabaseData &data);
|
||||
|
||||
/**
|
||||
* @brief Writes the snapshot to the binary cache for the current inputs.
|
||||
* @param data Snapshot to serialize.
|
||||
*/
|
||||
void saveToCache(const CardDatabaseData &data);
|
||||
|
||||
private:
|
||||
CardDatabase *database; /**< Non-owning pointer to the target CardDatabase. */
|
||||
ICardDatabasePathProvider *pathProvider; /**< Pointer to the path provider. */
|
||||
QList<ICardDatabaseParser *> availableParsers; /**< List of available parsers for different formats. */
|
||||
CardDatabase *database; /**< Non-owning pointer to the target CardDatabase. */
|
||||
ICardDatabasePathProvider *pathProvider; /**< Pointer to the path provider. */
|
||||
ICardSetPriorityController *priorityController; /**< Controller for reconstructing set state. */
|
||||
QList<ICardDatabaseParser *> availableParsers; /**< List of available parsers for different formats. */
|
||||
|
||||
QBasicMutex *loadFromFileMutex = new QBasicMutex(); /**< Mutex for single-file loading. */
|
||||
QBasicMutex *reloadDatabaseMutex = new QBasicMutex(); /**< Mutex for reloading entire database. */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue