Compare commits

..
Author SHA1 Message Date
Ian Chua 34fb16e921 fix: persist user id so that setting_id doesn't get wiped 2026-10-07 17:09:32 +08:00
10 changed files with 68 additions and 60 deletions
-2
View File
@@ -4094,8 +4094,6 @@ int CLI::run(int argc, char **argv)
flush_and_exit(CLI_MIXED_FILAMENT_INVALID);
}
}
if (filament_count > 0)
resize_mixed_filament_metadata(m_print_config, size_t(filament_count), size_t(filament_count));
m_print_config.option<ConfigOptionEnum<PrinterTechnology>>("printer_technology", true)->value = printer_technology;
+8 -2
View File
@@ -2337,7 +2337,7 @@ bool PresetCollection::reset_project_embedded_presets()
return re_select;
}
void PresetCollection::set_sync_info_and_save(std::string name, std::string setting_id, std::string syncinfo, long long update_time)
void PresetCollection::set_sync_info_and_save(std::string name, std::string setting_id, std::string syncinfo, long long update_time, const std::string& user_id)
{
lock();
const std::string canonical_name = this->canonical_preset_name(name);
@@ -2355,7 +2355,10 @@ void PresetCollection::set_sync_info_and_save(std::string name, std::string sett
preset2.save_info();
}
}
preset->setting_id = setting_id;
if (!setting_id.empty())
preset->setting_id = setting_id;
if (!user_id.empty())
preset->user_id = user_id;
if (update_time > 0)
preset->updated_time = update_time;
if (preset->sync_info == "update")
@@ -2645,6 +2648,9 @@ bool PresetCollection::load_user_preset(std::string name, std::map<std::string,
iter->base_id = based_id;
iter->filament_id = cloud_filament_id;
update_alias(*iter);
// Persist the cloud-assigned identity to disk, mirroring the equal/newer branch
// above; otherwise the id stays only in memory and the next launch rewrites it.
iter->save_info();
//presets_loaded.emplace_back(*it->second);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", update the user preset %1% from cloud, type %2%, setting_id %3%, base_id %4%, sync_info %5% inherits %6%, filament_id %7%")
% iter->name %Preset::get_type_string(m_type) %iter->setting_id %iter->base_id %iter->sync_info %iter->inherits() % iter->filament_id;
+1 -1
View File
@@ -603,7 +603,7 @@ public:
void update_after_user_presets_loaded();
//BBS: get user presets
int get_user_presets(PresetBundle *preset_bundle, std::vector<Preset> &result_presets);
void set_sync_info_and_save(std::string name, std::string setting_id, std::string syncinfo, long long update_time);
void set_sync_info_and_save(std::string name, std::string setting_id, std::string syncinfo, long long update_time, const std::string& user_id);
bool need_sync(std::string name, std::string setting_id, long long update_time);
//BBS: add function to generate differed preset for save
+18
View File
@@ -3601,6 +3601,24 @@ void PresetBundle::export_selections(AppConfig &config)
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": printer %1%, print %2%, filaments[0] %3% ")%printers.get_selected_preset_name() % prints.get_selected_preset_name() %filament_presets[0];
}
// Preserve metadata only for existing colour slots; new slots get false/empty defaults.
static void resize_mixed_filament_metadata(DynamicPrintConfig &config, size_t old_slot_count, size_t new_slot_count)
{
auto resize = [old_slot_count, new_slot_count](auto *opt) {
if (opt) {
opt->values.resize(std::min(old_slot_count, opt->values.size()));
opt->values.resize(new_slot_count);
}
};
resize(config.option<ConfigOptionBools>("filament_is_mixed"));
resize(config.option<ConfigOptionStrings>("filament_mixed_components"));
resize(config.option<ConfigOptionStrings>("filament_mixed_sublayer_ratios"));
resize(config.option<ConfigOptionBools>("filament_mixed_gradient"));
resize(config.option<ConfigOptionStrings>("filament_mixed_gradient_range"));
resize(config.option<ConfigOptionStrings>("filament_mixed_gradient_curve"));
resize(config.option<ConfigOptionBools>("filament_mixed_gradient_per_part"));
}
void PresetBundle::set_num_filaments(unsigned int n, std::string new_color)
{
unsigned old_filament_count = this->filament_presets.size();
-15
View File
@@ -10838,21 +10838,6 @@ void set_filament_dev_options(DynamicPrintConfig &config, const std::vector<cons
}
}
void resize_mixed_filament_metadata(DynamicPrintConfig &config, size_t old_slot_count, size_t new_slot_count)
{
auto resize = [old_slot_count, new_slot_count](auto *opt) {
opt->values.resize(std::min(old_slot_count, opt->values.size()));
opt->values.resize(new_slot_count);
};
resize(config.option<ConfigOptionBools>("filament_is_mixed", true));
resize(config.option<ConfigOptionStrings>("filament_mixed_components", true));
resize(config.option<ConfigOptionStrings>("filament_mixed_sublayer_ratios", true));
resize(config.option<ConfigOptionBools>("filament_mixed_gradient", true));
resize(config.option<ConfigOptionStrings>("filament_mixed_gradient_range", true));
resize(config.option<ConfigOptionStrings>("filament_mixed_gradient_curve", true));
resize(config.option<ConfigOptionBools>("filament_mixed_gradient_per_part", true));
}
//used for object/region config
//use the smallest of multiple to single
-4
View File
@@ -933,10 +933,6 @@ extern std::set<std::string> filament_dev_options;
// filament_configs, one config per filament in slot order, as the filaments' values one after another.
void set_filament_dev_options(DynamicPrintConfig &config, const std::vector<const DynamicPrintConfig *> &filament_configs);
// Orca: sizes the per-slot mixed-colour metadata options to new_slot_count, keeping the first
// old_slot_count values; an option the config lacks is created.
void resize_mixed_filament_metadata(DynamicPrintConfig &config, size_t old_slot_count, size_t new_slot_count);
extern void update_static_print_config_from_dynamic(ConfigBase& config, const DynamicPrintConfig& dest_config, std::vector<int> variant_index, std::set<std::string>& key_set1, int stride = 1);
extern void compute_filament_override_value(const std::string& opt_key, const ConfigOption *opt_old_machine, const ConfigOption *opt_new_machine, const ConfigOption *opt_new_filament, const DynamicPrintConfig& new_full_config,
t_config_option_keys& diff_keys, DynamicPrintConfig& filament_overrides, std::vector<int>& f_map_indices);
+4 -4
View File
@@ -7204,11 +7204,11 @@ void GUI_App::sync_preset(Preset* preset, bool force)
BOOST_LOG_TRIVIAL(trace) << "sync_preset: sync operation: " << preset->sync_info << " success! preset = " << preset->name;
if (preset->type == Preset::Type::TYPE_FILAMENT) {
preset_bundle->filaments.set_sync_info_and_save(preset->name, setting_id, updated_info, update_time);
preset_bundle->filaments.set_sync_info_and_save(preset->name, setting_id, updated_info, update_time, m_agent->get_user_id());
} else if (preset->type == Preset::Type::TYPE_PRINT) {
preset_bundle->prints.set_sync_info_and_save(preset->name, setting_id, updated_info, update_time);
preset_bundle->prints.set_sync_info_and_save(preset->name, setting_id, updated_info, update_time, m_agent->get_user_id());
} else if (preset->type == Preset::Type::TYPE_PRINTER) {
preset_bundle->printers.set_sync_info_and_save(preset->name, setting_id, updated_info, update_time);
preset_bundle->printers.set_sync_info_and_save(preset->name, setting_id, updated_info, update_time, m_agent->get_user_id());
}
}
}
@@ -7907,7 +7907,7 @@ void GUI_App::force_push_conflicting_preset(const std::string& setting_id)
? OrcaCloudServiceAgent::generate_uuid_for_setting_id(preset.name, user_id)
: preset.setting_id;
if (preset_id == setting_id) {
coll->set_sync_info_and_save(preset.name, setting_id, "update", 0);
coll->set_sync_info_and_save(preset.name, setting_id, "update", 0, user_id);
break;
}
}
+36 -12
View File
@@ -1129,6 +1129,19 @@ std::string OrcaCloudServiceAgent::request_setting_id(std::string name,
if (http_code)
*http_code = result.http_code;
// 409 duplicate_profile_uuid in the create path means the deterministic id we
// just generated already exists in this account: the earlier create succeeded.
// Adopt it instead of failing, so sync_preset persists the id and stops retrying.
if (result.http_code == 409 && result.conflict_code == -2
&& !result.server_version.id.empty() && result.server_version.id == new_id) {
if (values_map && result.server_version.updated_time != 0)
(*values_map)[IOT_JSON_KEY_UPDATED_TIME] = std::to_string(result.server_version.updated_time);
if (http_code)
*http_code = 200;
BOOST_LOG_TRIVIAL(info) << "OrcaCloudServiceAgent: request_setting_id adopted existing profile id " << new_id << " (409 duplicate_profile_uuid)";
return new_id;
}
if (result.success) {
if (values_map && result.new_updated_time != 0) {
(*values_map)[IOT_JSON_KEY_UPDATED_TIME] = std::to_string(result.new_updated_time);
@@ -1394,6 +1407,7 @@ SyncPushResult OrcaCloudServiceAgent::sync_push(const std::string& profile_id,
SyncPushResult result;
result.success = false;
result.http_code = 0;
result.conflict_code = 0;
result.server_deleted = false;
nlohmann::json body;
@@ -1429,20 +1443,30 @@ SyncPushResult OrcaCloudServiceAgent::sync_push(const std::string& profile_id,
err_body = json;
if (json.is_null()) {
result.server_deleted = true;
} else {
auto& profile_data = json["server_profile"];
result.server_version.id = profile_data.value("id", "");
result.server_version.name = profile_data.value("name", "");
result.server_version.updated_time = profile_data.value(ORCA_JSON_KEY_UPDATE_TIME, 0);
} else if (json.is_object()) {
result.conflict_code = json.value("code", 0);
if (json.contains("server_profile") && !json["server_profile"].is_null()) {
auto& profile_data = json["server_profile"];
result.server_version.id = profile_data.value("id", "");
result.server_version.name = profile_data.value("name", "");
result.server_version.updated_time = profile_data.value(ORCA_JSON_KEY_UPDATE_TIME, 0);
}
}
} catch (...) {}
// Surface the conflict via the http-error callback with the local preset name injected.
// The raw server body omits the name for tombstone (-3) conflicts (server_profile is null),
// but the GUI needs it to regenerate the deterministic setting_id for a force push.
if (!err_body.is_object())
err_body = nlohmann::json::object();
err_body["name"] = name;
invoke_http_error_callback(409, err_body.dump());
// Create-path duplicate_profile_uuid (-2) is an idempotent success: the deterministic id
// already exists, so the caller adopts the returned id. Skip the conflict notification,
// otherwise every already-imported preset would raise a Pull/Force-push prompt on each launch.
const bool is_create = original_updated_time.empty();
const bool auto_resolved_duplicate = (is_create && result.conflict_code == -2);
if (!auto_resolved_duplicate) {
// Surface the conflict via the http-error callback with the local preset name injected.
// The raw server body omits the name for tombstone (-3) conflicts (server_profile is null),
// but the GUI needs it to regenerate the deterministic setting_id for a force push.
if (!err_body.is_object())
err_body = nlohmann::json::object();
err_body["name"] = name;
invoke_http_error_callback(409, err_body.dump());
}
result.error_message = response;
return result;
}
@@ -94,6 +94,7 @@ struct SyncPullResponse {
struct SyncPushResult {
bool success;
int http_code;
int conflict_code;
long long new_updated_time;
ProfileUpsert server_version;
bool server_deleted;
@@ -826,23 +826,3 @@ TEST_CASE("The device drying options are rebuilt as each filament's values in sl
set_filament_dev_options(config, {&two_values, &no_value});
REQUIRE(config.option<ConfigOptionStrings>("filament_dev_ams_drying_ams_limitations")->values == std::vector<std::string>({"1", "0", ""}));
}
TEST_CASE("The mixed filament metadata is sized to the filament count", "[Config]")
{
DynamicPrintConfig config;
config.option<ConfigOptionBools>("filament_is_mixed", true)->values = {false, false, true};
config.option<ConfigOptionStrings>("filament_mixed_components", true)->values = {"", "", "1,2"};
config.option<ConfigOptionBools>("filament_mixed_gradient", true)->values = {false};
config.option<ConfigOptionStrings>("filament_mixed_gradient_range", true)->values = {""};
resize_mixed_filament_metadata(config, 3, 3);
REQUIRE(config.option<ConfigOptionBools>("filament_is_mixed")->values == std::vector<unsigned char>({false, false, true}));
REQUIRE(config.option<ConfigOptionStrings>("filament_mixed_components")->values == std::vector<std::string>({"", "", "1,2"}));
REQUIRE(config.option<ConfigOptionBools>("filament_mixed_gradient")->values == std::vector<unsigned char>({false, false, false}));
REQUIRE(config.option<ConfigOptionStrings>("filament_mixed_gradient_range")->values == std::vector<std::string>({"", "", ""}));
REQUIRE(config.option<ConfigOptionStrings>("filament_mixed_gradient_curve")->values == std::vector<std::string>({"", "", ""}));
resize_mixed_filament_metadata(config, 2, 4);
REQUIRE(config.option<ConfigOptionBools>("filament_is_mixed")->values == std::vector<unsigned char>({false, false, false, false}));
REQUIRE(config.option<ConfigOptionStrings>("filament_mixed_components")->values == std::vector<std::string>({"", "", "", ""}));
}