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

Method upsert_script_derived

components/stores/src/config.rs:338–376  ·  view source on GitHub ↗

Upserts the derived state observed for a script during a vm boot.

(
        &self,
        guild_id: Id<GuildMarker>,
        script_id: u64,
        update: UpdateScriptDerived,
    )

Source from the content-addressed store, hash-verified

336
337 /// Upserts the derived state observed for a script during a vm boot.
338 pub async fn upsert_script_derived(
339 &self,
340 guild_id: Id<GuildMarker>,
341 script_id: u64,
342 update: UpdateScriptDerived,
343 ) -> ConfigStoreResult<()> {
344 let commands_enc = serde_json::to_value(update.contributes.commands).unwrap();
345 let intervals_enc = serde_json::to_value(update.contributes.interval_timers).unwrap();
346 let settings_definitions_enc = serde_json::to_value(update.settings_definitions).unwrap();
347
348 sqlx::query!(
349 "
350 INSERT INTO guild_script_derived (script_id, guild_id, source_hash, \
351 settings_hash, runtime_version, contributes_commands, contributes_interval_timers, \
352 settings_definitions, updated_at)
353 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, now())
354 ON CONFLICT (script_id) DO UPDATE SET
355 source_hash = $3,
356 settings_hash = $4,
357 runtime_version = $5,
358 contributes_commands = $6,
359 contributes_interval_timers = $7,
360 settings_definitions = $8,
361 updated_at = now();
362 ",
363 script_id as i64,
364 guild_id.get() as i64,
365 update.source_hash,
366 update.settings_hash,
367 SCRIPT_RUNTIME_VERSION,
368 commands_enc,
369 intervals_enc,
370 settings_definitions_enc,
371 )
372 .execute(&self.pool)
373 .await?;
374
375 Ok(())
376 }
377
378 /// The inputs each of the guild's derived-state rows was observed under,
379 /// used to skip the [Self::upsert_script_derived] write when nothing changed.

Callers 1

Calls 1

executeMethod · 0.80

Tested by

no test coverage detected