You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: crates/djls-server/src/db.rs
+8-53Lines changed: 8 additions & 53 deletions
Original file line number
Diff line number
Diff line change
@@ -1,66 +1,21 @@
1
1
use salsa::Database;
2
2
3
-
/// A thread-safe handle to a Salsa database that can be shared between threads.
4
-
///
5
-
/// This implements the insight from [this Salsa Zulip discussion](https://salsa.zulipchat.com/#narrow/channel/145099-Using-Salsa/topic/.E2.9C.94.20Advice.20on.20using.20salsa.20from.20Sync.20.2B.20Send.20context/with/495497515)
6
-
/// where we're using the `StorageHandle` to create a thread-safe handle that can be
7
-
/// shared between threads. When we need to use it, we clone the handle to get a new reference.
Copy file name to clipboardExpand all lines: crates/djls-server/src/session.rs
+43-4Lines changed: 43 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,9 @@
1
1
use djls_conf::Settings;
2
2
use djls_project::DjangoProject;
3
+
use salsa::StorageHandle;
3
4
use tower_lsp_server::lsp_types::ClientCapabilities;
4
5
5
-
usecrate::db::ServerDatabaseHandle;
6
+
usecrate::db::ServerDatabase;
6
7
usecrate::documents::Store;
7
8
8
9
#[derive(Default)]
@@ -11,7 +12,32 @@ pub struct Session {
11
12
project:Option<DjangoProject>,
12
13
documents:Store,
13
14
settings:Settings,
14
-
db_handle:ServerDatabaseHandle,
15
+
16
+
/// A thread-safe Salsa database handle that can be shared between threads.
17
+
///
18
+
/// This implements the insight from [this Salsa Zulip discussion](https://salsa.zulipchat.com/#narrow/channel/145099-Using-Salsa/topic/.E2.9C.94.20Advice.20on.20using.20salsa.20from.20Sync.20.2B.20Send.20context/with/495497515)
19
+
/// where we're using the `StorageHandle` to create a thread-safe handle that can be
20
+
/// shared between threads. When we need to use it, we clone the handle to get a new reference.
21
+
///
22
+
/// Usage:
23
+
/// ```rust,ignore
24
+
/// // Use the StorageHandle in Session
25
+
/// let db_handle = StorageHandle::new(None);
26
+
///
27
+
/// // Clone it to pass to different threads
28
+
/// let db_handle_clone = db_handle.clone();
29
+
///
30
+
/// // Use it in an async context
31
+
/// async_fn(move || {
32
+
/// // Get a database from the handle
33
+
/// let storage = db_handle_clone.into_storage();
34
+
/// let db = ServerDatabase::new(storage);
35
+
///
36
+
/// // Use the database
37
+
/// db.some_query(args)
38
+
/// });
39
+
/// ```
40
+
db_handle:StorageHandle<ServerDatabase>,
15
41
}
16
42
17
43
implSession{
@@ -21,7 +47,7 @@ impl Session {
21
47
project:None,
22
48
documents:Store::new(),
23
49
settings:Settings::default(),
24
-
db_handle:ServerDatabaseHandle::new(),
50
+
db_handle:StorageHandle::new(None),
25
51
}
26
52
}
27
53
@@ -57,7 +83,20 @@ impl Session {
57
83
&mutself.settings
58
84
}
59
85
60
-
pubfndb_handle(&self) -> &ServerDatabaseHandle{
86
+
/// Get the raw database handle from the session
87
+
///
88
+
/// Note: In most cases, you'll want to use `db()` instead to get a usable
0 commit comments