MCPcopy Create free account
hub / github.com/Botloader/botloader / update_db_derived_state

Method update_db_derived_state

components/scheduler/src/guild_handler.rs:758–815  ·  view source on GitHub ↗
(
        &mut self,
        evt: &ScriptMeta,
        interval_contribs: Vec<IntervalTimerContrib>,
    )

Source from the content-addressed store, hash-verified

756 }
757
758 async fn update_db_derived_state(
759 &mut self,
760 evt: &ScriptMeta,
761 interval_contribs: Vec<IntervalTimerContrib>,
762 ) {
763 let script_id = evt.script_id.0;
764 let Some(script) = self.scripts.iter().find(|v| v.id == script_id) else {
765 warn!(script_id, "loaded script is not in the session script list");
766 return;
767 };
768
769 let source_hash = hash_script_source(&script.original_source);
770 let settings_hash = hash_settings_values(&script.settings_values);
771
772 if let Some(stored) = self.derived_freshness.get(&script_id) {
773 if stored.is_fresh(&source_hash, &settings_hash) {
774 return;
775 }
776 }
777
778 let twilight_commands = crate::command_manager::to_twilight_commands(
779 self.guild_id,
780 &evt.commands,
781 &evt.command_groups,
782 );
783
784 // TODO: handle errors here, maybe retry?
785 if let Err(err) = self
786 .stores
787 .upsert_script_derived(
788 self.guild_id,
789 script_id,
790 UpdateScriptDerived {
791 source_hash: source_hash.clone(),
792 settings_hash: settings_hash.clone(),
793 contributes: ScriptContributes {
794 commands: twilight_commands,
795 interval_timers: interval_contribs,
796 },
797 settings_definitions: evt.settings.clone(),
798 },
799 )
800 .await
801 {
802 error!(%err, script_id, "failed updating derived script state");
803 return;
804 }
805
806 self.derived_freshness.insert(
807 script_id,
808 ScriptDerivedFreshness {
809 script_id,
810 source_hash,
811 settings_hash,
812 runtime_version: SCRIPT_RUNTIME_VERSION.to_string(),
813 },
814 );
815 }

Callers 1

script_loadedMethod · 0.80

Calls 6

hash_script_sourceFunction · 0.85
hash_settings_valuesFunction · 0.85
to_twilight_commandsFunction · 0.85
is_freshMethod · 0.80
upsert_script_derivedMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected