Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ json5 = "0.4"
jsonwebtoken = { package = "spacetimedb-jsonwebtoken", version = "9.3.0" }
junction = "1"
jwks = { package = "spacetimedb-jwks", version = "0.1.3" }
lazy_static = "1.4.0"

lean_string = "0.5.1"
log = "0.4.17"
memchr = "2"
Expand Down
2 changes: 1 addition & 1 deletion crates/bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ criterion.workspace = true
futures.workspace = true
foldhash.workspace = true
hashbrown.workspace = true
lazy_static.workspace = true

log.workspace = true
mimalloc.workspace = true
rand.workspace = true
Expand Down
6 changes: 2 additions & 4 deletions crates/bench/benches/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use criterion::{
measurement::{Measurement, WallTime},
Bencher, BenchmarkGroup, Criterion,
};
use lazy_static::lazy_static;
use spacetimedb_bench::{
database::BenchDatabase,
schemas::{create_sequential, u32_u64_str, u32_u64_u64, BenchTable, IndexStrategy, RandomTable},
Expand All @@ -24,9 +23,8 @@ use tikv_jemallocator::Jemalloc;
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;

lazy_static! {
static ref RUN_ONE_MILLION: bool = std::env::var("RUN_ONE_MILLION").is_ok();
}
static RUN_ONE_MILLION: std::sync::LazyLock<bool> =
std::sync::LazyLock::new(|| std::env::var("RUN_ONE_MILLION").is_ok());

fn criterion_benchmark(c: &mut Criterion) {
bench_suite::<sqlite::SQLite>(c, true).unwrap();
Expand Down
6 changes: 0 additions & 6 deletions crates/bench/src/bin/summarize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ fn main() {
mod criterion {
use std::path::{Path, PathBuf};

use regex::Regex;

pub fn pack(baseline_name: String, target_dir: &Path) {
assert!(
!baseline_name.ends_with(".json"),
Expand Down Expand Up @@ -102,10 +100,6 @@ mod criterion {
crit_dir.join(format!("{name}.json"))
}

lazy_static::lazy_static! {
static ref EMOJI: Regex = Regex::new(r"(on_disk|mem)").unwrap();
}

/// Data types for deserializing stored Criterion benchmark results.
///
/// Unfortunately, there is no published library for this, so we use the schema
Expand Down
13 changes: 5 additions & 8 deletions crates/bench/src/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
schemas::{table_name, BenchTable, IndexStrategy},
ResultBench,
};
use lazy_static::lazy_static;

use rusqlite::Connection;
use spacetimedb_data_structures::map::HashMap;
use spacetimedb_lib::sats::{AlgebraicType, AlgebraicValue, ProductType};
Expand All @@ -12,7 +12,7 @@ use spacetimedb_schema::table_name::TableName;
use std::{
fmt::Write,
hint::black_box,
sync::{Arc, RwLock},
sync::{Arc, LazyLock, RwLock},
};
use tempdir::TempDir;

Expand Down Expand Up @@ -253,12 +253,9 @@ fn memo_query<F: FnOnce() -> String>(bench_name: BenchName, table_id: &str, gene
}
}

lazy_static! {
// bench_name -> table_id -> query.
// Double hashmap is necessary because of tuple dereferencing problems.
static ref QUERIES: RwLock<HashMap<BenchName, HashMap<String, Arc<str>>>> =
RwLock::default();
}
// bench_name -> table_id -> query.
// Double hashmap is necessary because of tuple dereferencing problems.
static QUERIES: LazyLock<RwLock<HashMap<BenchName, HashMap<String, Arc<str>>>>> = LazyLock::new(RwLock::default);

#[inline(never)]
fn insert_template(table_id: &str, product_type: ProductType) -> String {
Expand Down
2 changes: 1 addition & 1 deletion crates/client-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spacetimedb-schema.workspace = true

base64.workspace = true
tokio = { version = "1.2", features = ["full"] }
lazy_static = "1.4.0"

log = "0.4.4"
serde = "1.0.136"
serde_json = { version = "1.0", features = ["raw_value"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ imara-diff.workspace = true
indexmap.workspace = true
itertools.workspace = true
jsonwebtoken.workspace = true
lazy_static.workspace = true

log.workspace = true
memchr.workspace = true
nohash-hasher.workspace = true
Expand Down
8 changes: 3 additions & 5 deletions crates/core/src/auth/token_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub use jsonwebtoken::errors::ErrorKind as JwtErrorKind;
use jsonwebtoken::{decode, Validation};
pub use jsonwebtoken::{DecodingKey, EncodingKey};
use jwks::Jwks;
use lazy_static::lazy_static;

use serde::Serialize;
use std::sync::Arc;
use std::time::Duration;
Expand Down Expand Up @@ -137,10 +137,8 @@ struct BasicTokenValidator {
pub issuer: Option<Box<str>>,
}

lazy_static! {
// Eventually we will want to add more required claims.
static ref REQUIRED_CLAIMS: Vec<&'static str> = vec!["sub", "iss"];
}
// Eventually we will want to add more required claims.
const REQUIRED_CLAIMS: [&str; 2] = ["sub", "iss"];
Comment on lines +140 to +141
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seemed like it should have been const, can change to static though if I'm missing something.


#[async_trait]
impl TokenValidator for DecodingKey {
Expand Down
2 changes: 1 addition & 1 deletion crates/datastore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ derive_more.workspace = true
enum-as-inner.workspace = true
enum-map.workspace = true
itertools.workspace = true
lazy_static.workspace = true

log.workspace = true
once_cell.workspace = true
parking_lot.workspace = true
Expand Down
179 changes: 86 additions & 93 deletions crates/datastore/src/system_tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use spacetimedb_table::table::RowRef;
use std::borrow::Cow;
use std::cell::RefCell;
use std::str::FromStr;
use std::sync::LazyLock;
use strum::Display;
use v9::{RawModuleDefV9Builder, TableType};

Expand Down Expand Up @@ -697,107 +698,99 @@ fn system_module_def() -> ModuleDef {
result
}

lazy_static::lazy_static! {
/// The canonical definition of the system tables.
///
/// It's important not to leak this `ModuleDef` or the `Def`s it contains outside this file.
/// You should only return `Schema`s from this file, not `Def`s!
///
/// This is because `SYSTEM_MODULE_DEF` has a `Typespace` that is DISTINCT from the typespace used in the client module.
/// System `TableDef`s refer to this typespace, but client `TableDef`s refer to the client typespace.
/// This could easily result in confusing errors!
/// Fortunately, when converting from `TableDef` to `TableSchema`, all `AlgebraicType`s are resolved,
/// so that they are self-contained and do not refer to any `Typespace`.
static ref SYSTEM_MODULE_DEF: ModuleDef = system_module_def();
}
/// The canonical definition of the system tables.
///
/// It's important not to leak this `ModuleDef` or the `Def`s it contains outside this file.
/// You should only return `Schema`s from this file, not `Def`s!
///
/// This is because `SYSTEM_MODULE_DEF` has a `Typespace` that is DISTINCT from the typespace used in the client module.
/// System `TableDef`s refer to this typespace, but client `TableDef`s refer to the client typespace.
/// This could easily result in confusing errors!
/// Fortunately, when converting from `TableDef` to `TableSchema`, all `AlgebraicType`s are resolved,
/// so that they are self-contained and do not refer to any `Typespace`.
static SYSTEM_MODULE_DEF: LazyLock<ModuleDef> = LazyLock::new(system_module_def);

lazy_static::lazy_static! {
// We enumerate the constraints used by system tables here, so that we can assign them stable IDs.
// When adding a new index, we just need to make sure we are incrementing the last ID used.
pub static ref CONSTRAINT_IDS: HashMap<&'static str, ConstraintId> = {
let mut m = HashMap::new();
m.insert("st_table_table_id_key", ConstraintId(1));
m.insert("st_table_table_name_key", ConstraintId(2));
m.insert("st_column_table_id_col_pos_key", ConstraintId(3));
m.insert("st_sequence_sequence_id_key", ConstraintId(4));
m.insert("st_index_index_id_key", ConstraintId(5));
m.insert("st_constraint_constraint_id_key", ConstraintId(6));
m.insert("st_client_identity_connection_id_key", ConstraintId(7));
m.insert("st_var_name_key", ConstraintId(8));
m.insert("st_scheduled_schedule_id_key", ConstraintId(9));
m.insert("st_scheduled_table_id_key", ConstraintId(10));
m.insert("st_row_level_security_sql_key", ConstraintId(11));
m.insert("st_connection_credentials_connection_id_key", ConstraintId(12));
m.insert("st_view_view_id_key", ConstraintId(13));
m.insert("st_view_view_name_key", ConstraintId(14));
m.insert("st_view_param_view_id_param_pos_key", ConstraintId(15));
m.insert("st_view_column_view_id_col_pos_key", ConstraintId(16));
m.insert("st_view_arg_id_key", ConstraintId(17));
m.insert("st_view_arg_bytes_key", ConstraintId(18));
m.insert("st_event_table_table_id_key", ConstraintId(19));
m.insert("st_table_accessor_table_name_key", ConstraintId(20));
m.insert("st_table_accessor_accessor_name_key", ConstraintId(21));
m.insert("st_index_accessor_index_name_key", ConstraintId(22));
m.insert("st_index_accessor_accessor_name_key", ConstraintId(23));
m.insert("st_column_accessor_table_name_col_name_key", ConstraintId(24));
m.insert("st_column_accessor_table_name_accessor_name_key", ConstraintId(25));
m
};
}

lazy_static::lazy_static! {
pub static CONSTRAINT_IDS: LazyLock<HashMap<&'static str, ConstraintId>> = LazyLock::new(|| {
let mut m = HashMap::new();
m.insert("st_table_table_id_key", ConstraintId(1));
m.insert("st_table_table_name_key", ConstraintId(2));
m.insert("st_column_table_id_col_pos_key", ConstraintId(3));
m.insert("st_sequence_sequence_id_key", ConstraintId(4));
m.insert("st_index_index_id_key", ConstraintId(5));
m.insert("st_constraint_constraint_id_key", ConstraintId(6));
m.insert("st_client_identity_connection_id_key", ConstraintId(7));
m.insert("st_var_name_key", ConstraintId(8));
m.insert("st_scheduled_schedule_id_key", ConstraintId(9));
m.insert("st_scheduled_table_id_key", ConstraintId(10));
m.insert("st_row_level_security_sql_key", ConstraintId(11));
m.insert("st_connection_credentials_connection_id_key", ConstraintId(12));
m.insert("st_view_view_id_key", ConstraintId(13));
m.insert("st_view_view_name_key", ConstraintId(14));
m.insert("st_view_param_view_id_param_pos_key", ConstraintId(15));
m.insert("st_view_column_view_id_col_pos_key", ConstraintId(16));
m.insert("st_view_arg_id_key", ConstraintId(17));
m.insert("st_view_arg_bytes_key", ConstraintId(18));
m.insert("st_event_table_table_id_key", ConstraintId(19));
m.insert("st_table_accessor_table_name_key", ConstraintId(20));
m.insert("st_table_accessor_accessor_name_key", ConstraintId(21));
m.insert("st_index_accessor_index_name_key", ConstraintId(22));
m.insert("st_index_accessor_accessor_name_key", ConstraintId(23));
m.insert("st_column_accessor_table_name_col_name_key", ConstraintId(24));
m.insert("st_column_accessor_table_name_accessor_name_key", ConstraintId(25));
m
});

// We enumerate the indexes used by system tables here, so that we can assign them stable IDs.
// When adding a new index, we just need to make sure we are incrementing the last ID used.
pub static ref INDEX_IDS: HashMap<&'static str, IndexId> = {
let mut m = HashMap::new();
m.insert("st_table_table_id_idx_btree", IndexId(1));
m.insert("st_table_table_name_idx_btree", IndexId(2));
m.insert("st_column_table_id_col_pos_idx_btree", IndexId(3));
m.insert("st_sequence_sequence_id_idx_btree", IndexId(4));
m.insert("st_index_index_id_idx_btree", IndexId(5));
m.insert("st_constraint_constraint_id_idx_btree", IndexId(6));
m.insert("st_client_identity_connection_id_idx_btree", IndexId(7));
m.insert("st_var_name_idx_btree", IndexId(8));
m.insert("st_scheduled_schedule_id_idx_btree", IndexId(9));
m.insert("st_scheduled_table_id_idx_btree", IndexId(10));
m.insert("st_row_level_security_table_id_idx_btree", IndexId(11));
m.insert("st_row_level_security_sql_idx_btree", IndexId(12));
m.insert("st_connection_credentials_connection_id_idx_btree", IndexId(13));
m.insert("st_view_view_id_idx_btree", IndexId(14));
m.insert("st_view_view_name_idx_btree", IndexId(15));
m.insert("st_view_param_view_id_param_pos_idx_btree", IndexId(16));
m.insert("st_view_column_view_id_col_pos_idx_btree", IndexId(17));
m.insert("st_view_sub_identity_idx_btree", IndexId(18));
m.insert("st_view_sub_has_subscribers_idx_btree", IndexId(19));
m.insert("st_view_sub_view_id_arg_id_identity_idx_btree", IndexId(20));
m.insert("st_view_arg_id_idx_btree", IndexId(21));
m.insert("st_view_arg_bytes_idx_btree", IndexId(22));
m.insert("st_event_table_table_id_idx_btree", IndexId(23));
m.insert("st_table_accessor_table_name_idx_btree", IndexId(24));
m.insert("st_table_accessor_accessor_name_idx_btree", IndexId(25));
m.insert("st_index_accessor_index_name_idx_btree", IndexId(26));
m.insert("st_index_accessor_accessor_name_idx_btree", IndexId(27));
m.insert("st_column_accessor_table_name_col_name_idx_btree", IndexId(28));
m.insert("st_column_accessor_table_name_accessor_name_idx_btree", IndexId(29));
m
};
}
pub static INDEX_IDS: LazyLock<HashMap<&'static str, IndexId>> = LazyLock::new(|| {
let mut m = HashMap::new();
m.insert("st_table_table_id_idx_btree", IndexId(1));
m.insert("st_table_table_name_idx_btree", IndexId(2));
m.insert("st_column_table_id_col_pos_idx_btree", IndexId(3));
m.insert("st_sequence_sequence_id_idx_btree", IndexId(4));
m.insert("st_index_index_id_idx_btree", IndexId(5));
m.insert("st_constraint_constraint_id_idx_btree", IndexId(6));
m.insert("st_client_identity_connection_id_idx_btree", IndexId(7));
m.insert("st_var_name_idx_btree", IndexId(8));
m.insert("st_scheduled_schedule_id_idx_btree", IndexId(9));
m.insert("st_scheduled_table_id_idx_btree", IndexId(10));
m.insert("st_row_level_security_table_id_idx_btree", IndexId(11));
m.insert("st_row_level_security_sql_idx_btree", IndexId(12));
m.insert("st_connection_credentials_connection_id_idx_btree", IndexId(13));
m.insert("st_view_view_id_idx_btree", IndexId(14));
m.insert("st_view_view_name_idx_btree", IndexId(15));
m.insert("st_view_param_view_id_param_pos_idx_btree", IndexId(16));
m.insert("st_view_column_view_id_col_pos_idx_btree", IndexId(17));
m.insert("st_view_sub_identity_idx_btree", IndexId(18));
m.insert("st_view_sub_has_subscribers_idx_btree", IndexId(19));
m.insert("st_view_sub_view_id_arg_id_identity_idx_btree", IndexId(20));
m.insert("st_view_arg_id_idx_btree", IndexId(21));
m.insert("st_view_arg_bytes_idx_btree", IndexId(22));
m.insert("st_event_table_table_id_idx_btree", IndexId(23));
m.insert("st_table_accessor_table_name_idx_btree", IndexId(24));
m.insert("st_table_accessor_accessor_name_idx_btree", IndexId(25));
m.insert("st_index_accessor_index_name_idx_btree", IndexId(26));
m.insert("st_index_accessor_accessor_name_idx_btree", IndexId(27));
m.insert("st_column_accessor_table_name_col_name_idx_btree", IndexId(28));
m.insert("st_column_accessor_table_name_accessor_name_idx_btree", IndexId(29));
m
});

// We enumerate of the sequences used by system tables here, so that we can assign them stable IDs.
// When adding a new sequence, we just need to make sure we are incrementing the last ID used.
lazy_static::lazy_static! {
pub static ref SEQUENCE_IDS: HashMap<&'static str, SequenceId> = {
let mut m = HashMap::new();
m.insert("st_table_table_id_seq", SequenceId(1));
m.insert("st_index_index_id_seq", SequenceId(2));
m.insert("st_constraint_constraint_id_seq", SequenceId(3));
m.insert("st_scheduled_schedule_id_seq", SequenceId(4));
m.insert("st_sequence_sequence_id_seq", SequenceId(5));
m.insert("st_view_view_id_seq", SequenceId(6));
m.insert("st_view_arg_id_seq", SequenceId(7));
m
};
}
pub static SEQUENCE_IDS: LazyLock<HashMap<&'static str, SequenceId>> = LazyLock::new(|| {
let mut m = HashMap::new();
m.insert("st_table_table_id_seq", SequenceId(1));
m.insert("st_index_index_id_seq", SequenceId(2));
m.insert("st_constraint_constraint_id_seq", SequenceId(3));
m.insert("st_scheduled_schedule_id_seq", SequenceId(4));
m.insert("st_sequence_sequence_id_seq", SequenceId(5));
m.insert("st_view_view_id_seq", SequenceId(6));
m.insert("st_view_arg_id_seq", SequenceId(7));
m
});

fn st_schema(name: &str, id: TableId) -> TableSchema {
let mut result = TableSchema::from_module_def(
Expand Down
2 changes: 1 addition & 1 deletion crates/schema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ anyhow.workspace = true
derive_more.workspace = true
indexmap.workspace = true
itertools.workspace = true
lazy_static.workspace = true

lean_string.workspace = true
thiserror.workspace = true
unicode-ident.workspace = true
Expand Down
Loading