Skip to content
Open
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
21 changes: 17 additions & 4 deletions rivetkit-typescript/packages/sqlite-native/src/vfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@

fn read_cache_enabled() -> bool {
static READ_CACHE_ENABLED: OnceLock<bool> = OnceLock::new();

Check warning on line 108 in rivetkit-typescript/packages/sqlite-native/src/vfs.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/rivet/rivet/rivetkit-typescript/packages/sqlite-native/src/vfs.rs
*READ_CACHE_ENABLED.get_or_init(|| {
std::env::var(READ_CACHE_ENV_VAR)
.map(|value| matches!(value.to_ascii_lowercase().as_str(), "1" | "true" | "yes" | "on"))
Expand Down Expand Up @@ -574,6 +574,7 @@
chunk_offset: usize,
write_start: usize,
write_end: usize,
cached_chunk: Option<Vec<u8>>,
existing_chunk_index: Option<usize>,
}

Expand All @@ -590,7 +591,13 @@
};
let needs_existing = write_start > 0 || existing_bytes_in_chunk > write_end;
let chunk_key = kv::get_chunk_key(file.file_tag, chunk_idx as u32).to_vec();
let existing_chunk_index = if needs_existing {
let cached_chunk = if needs_existing && ctx.read_cache_enabled {
let state = get_file_state(file.state);
state.read_cache.get(chunk_key.as_slice()).cloned()

Check failure on line 596 in rivetkit-typescript/packages/sqlite-native/src/vfs.rs

View workflow job for this annotation

GitHub Actions / Check

no method named `get` found for enum `Option<T>` in the current scope
} else {
None
};
let existing_chunk_index = if needs_existing && cached_chunk.is_none() {
let idx = chunk_keys_to_fetch.len();
chunk_keys_to_fetch.push(chunk_key.clone());
Some(idx)
Expand All @@ -603,6 +610,7 @@
chunk_offset,
write_start,
write_end,
cached_chunk,
existing_chunk_index,
});
}
Expand All @@ -621,13 +629,18 @@
Err(_) => return SQLITE_IOERR_WRITE,
}
};

Check warning on line 632 in rivetkit-typescript/packages/sqlite-native/src/vfs.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/rivet/rivet/rivetkit-typescript/packages/sqlite-native/src/vfs.rs
let mut entries_to_write = Vec::with_capacity(plans.len() + 1);
for plan in &plans {
let existing_chunk = plan
.existing_chunk_index
.and_then(|idx| existing_chunks.get(idx))
.and_then(|value| value.as_ref());
.cached_chunk
.as_deref()
.or_else(|| {
plan

Check failure on line 639 in rivetkit-typescript/packages/sqlite-native/src/vfs.rs

View workflow job for this annotation

GitHub Actions / Check

mismatched types
.existing_chunk_index
.and_then(|idx| existing_chunks.get(idx))
.and_then(|value| value.as_ref())
});

let mut new_chunk = if let Some(existing_chunk) = existing_chunk {
let mut chunk = vec![0u8; std::cmp::max(existing_chunk.len(), plan.write_end)];
Expand Down Expand Up @@ -908,7 +921,7 @@
state.batch_mode = false;
return SQLITE_IOERR;
}

Check warning on line 924 in rivetkit-typescript/packages/sqlite-native/src/vfs.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/rivet/rivet/rivetkit-typescript/packages/sqlite-native/src/vfs.rs
// Move dirty buffer entries into the read cache so subsequent
// reads can serve them without a KV round-trip.
let flushed: Vec<_> = std::mem::take(&mut state.dirty_buffer).into_iter().collect();
Expand Down
Loading