mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-17 14:02:35 +00:00
* Add caching system for presets * Removing user\bundle serialization and keeping it only for system presets * Integrate caching into WebGuideDialog which speeds up time of SetupWizzard and PrinterSelection dialog * Add CI\CD step to prepare cache file in ahead of time so user does not need to wait * Add partial cache generation when only one of the vendros is changed to speed up recalculation time * Handle corrupted files * Add cache to GuideDialog as previos version didn't work as expected * Add inspecting tool and fix CI cache generation * Generate cache per vendor * Simplify code by mergin it in PresetBundle * Simplify code a bit more * Add cereal serialize() to VendorProfile, PrinterModel, Preset, and Semver * Remove CachedPrinterModel/VendorProfile/Preset mirror structs from VendorCache * Fix use-after-free in CallAfter lambda; replace raw thread pointer with unique_ptr * Use get_vendor_cache_key() to match cache keys written by the app * Remove BOM added by VSC * Skip invalid vendors * Remove leftover cache file * Fix build for windows arm64 * Revert json cache back * Update check for stale cache * Serealize all value fields for Preset class to minimize regression later * Minimize field duplication by moving Cache thing into PresetBundle * Add tests for Cache system * Add a bit more tests * Merge branch 'main' into feature/cache_profiles_and_optimize_loading_speed * Rvert from per-verndor to single cache file Replace N per-vendor .cache files with a single system_presets.cache that holds all vendors and presets in one serialized blob. Cache load is now all-or-nothing: on hit all vendors are applied from the bundle (sub-second); on miss all vendors are parsed from JSON and a fresh bundle is written to the user cache dir. Invalidation is driven by bundle_key - a sorted concatenation of all vendor JSON version strings. Any vendor update invalidates the whole cache and triggers re-parse on next launch. Guide wizard (WebGuideDialog) loads the bundled cache into a plain PresetBundle instead of a separate VendorGuideData struct, removing the duplicate data model. generate_system_cache simplified from a per-vendor loop to a single save_system_presets_cache() call producing one output file. * Transfer all Preset fields from cache via move assignmet apply_vendor_preset_group was copying fields manually and missed bundle_id, user_id, base_id, sync_info, updated_time, key_values, ini_str. Replace field-by-field copy with move assignment of the fully-deserialized Preset, then restore the vendor pointer which is excluded from serialization. * Ignore cache for future * Remove not used files * Ship one preset cache per vendor in place of the profile JSONs Each vendor's system presets serialize into a single <vendor>.opc built at package time, and a shipped build carries that file alone — the profile JSON and its sub-file tree are pruned. The vendor loader, the setup wizard's profile list and the resource installer all read a vendor through its cache, falling back to parsing whenever one is absent, stale or unreadable, so the cache stays an optimization and never a source of truth. Caches hold presets in source form and resolve inheritance at load, through the same code the JSON path uses. * Make the preset cache self-describing and load each vendor from the system folder alone The cached DynamicPrintConfig is keyed by name, through a per-file dictionary of the distinct opt_keys, the type each was written as, and the distinct enum value names, instead of by serialization_key_ordinal — a position assigned by declaration order at static init, where inserting one option shifts every later ordinal and the lookup then succeeds on the wrong option. Because a name-keyed payload drops the options this build cannot place rather than being rejected wholesale, the schema fingerprint goes, and with it the two fallbacks that existed only because an installed cache died on every app upgrade: the second lookup tier into resources/profiles and the parse fallback to the same place. A vendor is loaded from <data_dir>/system/ and nowhere else, as on main — which is what makes the app write its .opc files there again. * Simplify the preset cache internals after review * Use the shared temp-dir helper in the preset bundle loading test * Bound stamp string reads in the preset cache * Speed up the setup wizard with a profile-data cache The wizard's per-vendor fast path threw on vendors present only in resources, falling back to a ~29 s raw JSON scan on every open. Each vendor now loads from the directory it was found in, and the derived model/machine/filament/process catalog is cached whole in <data_dir>/cache/wizard_profile_data.json, stamped by each vendor's name and version - a fresh cache makes an open one file read, with no bundle built and no presets installed (~0.2 s vs ~2 s). * Remove debug SVG dump from a geometry test * Move the per-vendor cache file format into PresetCacheFormat * Move the vendor install helpers from PresetBundle into Utils * rename * fix flatpak * change cache version to 1 --------- Co-authored-by: SoftFever <softfeverever@gmail.com>
218 lines
6.8 KiB
C++
218 lines
6.8 KiB
C++
#ifndef slic3r_Semver_hpp_
|
|
#define slic3r_Semver_hpp_
|
|
|
|
#include <string>
|
|
#include <cstring>
|
|
#include <ostream>
|
|
#include <stdexcept>
|
|
#include <boost/optional.hpp>
|
|
#include <boost/format.hpp>
|
|
|
|
#include "semver/semver.h"
|
|
|
|
#include "Exception.hpp"
|
|
|
|
namespace Slic3r {
|
|
|
|
|
|
class Semver
|
|
{
|
|
public:
|
|
struct Major { const int i; Major(int i) : i(i) {} };
|
|
struct Minor { const int i; Minor(int i) : i(i) {} };
|
|
struct Patch { const int i; Patch(int i) : i(i) {} };
|
|
|
|
Semver() : ver(semver_zero()) {}
|
|
|
|
Semver(int major, int minor, int patch,
|
|
boost::optional<const std::string&> metadata, boost::optional<const std::string&> prerelease)
|
|
: ver(semver_zero())
|
|
{
|
|
ver.major = major;
|
|
ver.minor = minor;
|
|
ver.patch = patch;
|
|
set_metadata(metadata);
|
|
set_prerelease(prerelease);
|
|
}
|
|
|
|
Semver(int major, int minor, int patch, const char *metadata = nullptr, const char *prerelease = nullptr)
|
|
: ver(semver_zero())
|
|
{
|
|
ver.major = major;
|
|
ver.minor = minor;
|
|
ver.patch = patch;
|
|
set_metadata(metadata);
|
|
set_prerelease(prerelease);
|
|
}
|
|
|
|
Semver(const std::string &str) : ver(semver_zero())
|
|
{
|
|
auto parsed = parse(str);
|
|
if (! parsed) {
|
|
throw Slic3r::RuntimeError(std::string("Could not parse version string: ") + str);
|
|
}
|
|
ver = parsed->ver;
|
|
parsed->ver = semver_zero();
|
|
}
|
|
|
|
static boost::optional<Semver> parse(const std::string &str)
|
|
{
|
|
semver_t ver = semver_zero();
|
|
if (::semver_parse(str.c_str(), &ver) == 0) {
|
|
return Semver(ver);
|
|
} else {
|
|
return boost::none;
|
|
}
|
|
}
|
|
|
|
static const Semver zero() { return Semver(semver_zero()); }
|
|
|
|
static const Semver inf()
|
|
{
|
|
static semver_t ver = { std::numeric_limits<int>::max(), std::numeric_limits<int>::max(), std::numeric_limits<int>::max(), nullptr, nullptr };
|
|
return Semver(ver);
|
|
}
|
|
|
|
static const Semver invalid()
|
|
{
|
|
static semver_t ver = { -1, 0, 0, nullptr, nullptr };
|
|
return Semver(ver);
|
|
}
|
|
|
|
Semver(Semver &&other) : ver(other.ver) { other.ver = semver_zero(); }
|
|
Semver(const Semver &other) : ver(::semver_copy(&other.ver)) {}
|
|
|
|
Semver &operator=(Semver &&other)
|
|
{
|
|
::semver_free(&ver);
|
|
ver = other.ver;
|
|
other.ver = semver_zero();
|
|
return *this;
|
|
}
|
|
|
|
Semver &operator=(const Semver &other)
|
|
{
|
|
::semver_free(&ver);
|
|
ver = ::semver_copy(&other.ver);
|
|
return *this;
|
|
}
|
|
|
|
~Semver() { ::semver_free(&ver); }
|
|
|
|
// const accessors
|
|
int maj() const { return ver.major; }
|
|
int min() const { return ver.minor; }
|
|
int patch() const { return ver.patch; }
|
|
const char* prerelease() const { return ver.prerelease; }
|
|
const char* metadata() const { return ver.metadata; }
|
|
|
|
// Setters
|
|
void set_maj(int maj) { ver.major = maj; }
|
|
void set_min(int min) { ver.minor = min; }
|
|
void set_patch(int patch) { ver.patch = patch; }
|
|
void set_metadata(boost::optional<const std::string &> meta)
|
|
{
|
|
if (ver.metadata)
|
|
free(ver.metadata);
|
|
ver.metadata = meta ? strdup(*meta) : nullptr;
|
|
}
|
|
void set_metadata(const char *meta)
|
|
{
|
|
if (ver.metadata)
|
|
free(ver.metadata);
|
|
ver.metadata = meta ? strdup(meta) : nullptr;
|
|
}
|
|
void set_prerelease(boost::optional<const std::string &> pre)
|
|
{
|
|
if (ver.prerelease)
|
|
free(ver.prerelease);
|
|
ver.prerelease = pre ? strdup(*pre) : nullptr;
|
|
}
|
|
void set_prerelease(const char *pre)
|
|
{
|
|
if (ver.prerelease)
|
|
free(ver.prerelease);
|
|
ver.prerelease = pre ? strdup(pre) : nullptr;
|
|
}
|
|
|
|
// Comparison
|
|
bool operator<(const Semver &b) const { return ::semver_compare(ver, b.ver) == -1; }
|
|
bool operator<=(const Semver &b) const { return ::semver_compare(ver, b.ver) <= 0; }
|
|
bool operator==(const Semver &b) const { return ::semver_compare(ver, b.ver) == 0; }
|
|
bool operator!=(const Semver &b) const { return ::semver_compare(ver, b.ver) != 0; }
|
|
bool operator>=(const Semver &b) const { return ::semver_compare(ver, b.ver) >= 0; }
|
|
bool operator>(const Semver &b) const { return ::semver_compare(ver, b.ver) == 1; }
|
|
// We're using '&' instead of the '~' operator here as '~' is unary-only:
|
|
// Satisfies patch if Major and minor are equal.
|
|
bool operator&(const Semver &b) const { return ::semver_satisfies_patch(ver, b.ver) != 0; }
|
|
bool operator^(const Semver &b) const { return ::semver_satisfies_caret(ver, b.ver) != 0; }
|
|
bool in_range(const Semver &low, const Semver &high) const { return low <= *this && *this <= high; }
|
|
bool valid() const { return *this != zero() && *this != inf() && *this != invalid(); }
|
|
|
|
// Conversion
|
|
std::string to_string() const {
|
|
//BBS: version format
|
|
std::string res;
|
|
int patch_1 = ver.patch/100;
|
|
int patch_2 = ver.patch%100;
|
|
res = (boost::format("%1%.%2%.%3%.%4%") % ver.major % ver.minor % patch_1 % patch_2).str();
|
|
|
|
if (ver.prerelease != nullptr) { res += '-'; res += ver.prerelease; }
|
|
if (ver.metadata != nullptr) { res += '+'; res += ver.metadata; }
|
|
return res;
|
|
}
|
|
std::string to_string_sf() const {
|
|
//BBS: version format
|
|
std::string res;
|
|
res = (boost::format("%1%.%2%.%3%") % ver.major % ver.minor % ver.patch).str();
|
|
|
|
if (ver.prerelease != nullptr) { res += '-'; res += ver.prerelease; }
|
|
if (ver.metadata != nullptr) { res += '+'; res += ver.metadata; }
|
|
return res;
|
|
}
|
|
|
|
// Arithmetics
|
|
Semver& operator+=(const Major &b) { ver.major += b.i; return *this; }
|
|
Semver& operator+=(const Minor &b) { ver.minor += b.i; return *this; }
|
|
Semver& operator+=(const Patch &b) { ver.patch += b.i; return *this; }
|
|
Semver& operator-=(const Major &b) { ver.major -= b.i; return *this; }
|
|
Semver& operator-=(const Minor &b) { ver.minor -= b.i; return *this; }
|
|
Semver& operator-=(const Patch &b) { ver.patch -= b.i; return *this; }
|
|
Semver operator+(const Major &b) const { Semver res(*this); return res += b; }
|
|
Semver operator+(const Minor &b) const { Semver res(*this); return res += b; }
|
|
Semver operator+(const Patch &b) const { Semver res(*this); return res += b; }
|
|
Semver operator-(const Major &b) const { Semver res(*this); return res -= b; }
|
|
Semver operator-(const Minor &b) const { Semver res(*this); return res -= b; }
|
|
Semver operator-(const Patch &b) const { Semver res(*this); return res -= b; }
|
|
|
|
// Stream output
|
|
friend std::ostream& operator<<(std::ostream& os, const Semver &self) {
|
|
os << self.to_string();
|
|
return os;
|
|
}
|
|
|
|
// cereal: round-trip through the standard 3-part string (major.minor.patch).
|
|
// to_string() uses a BBS 4-part format that semver_parse() cannot read back.
|
|
template<class Archive>
|
|
std::string save_minimal(const Archive&) const { return to_string_sf(); }
|
|
template<class Archive>
|
|
void load_minimal(const Archive&, const std::string& s) {
|
|
auto v = Semver::parse(s);
|
|
if (! v)
|
|
throw std::runtime_error("Semver: cannot parse serialized version: " + s);
|
|
*this = std::move(*v);
|
|
}
|
|
|
|
private:
|
|
semver_t ver;
|
|
|
|
Semver(semver_t ver) : ver(ver) {}
|
|
|
|
static semver_t semver_zero() { return { 0, 0, 0, nullptr, nullptr }; }
|
|
static char * strdup(const std::string &str) { return ::semver_strdup(str.data()); }
|
|
};
|
|
|
|
|
|
}
|
|
#endif
|