Skip to content

Commit 0922c14

Browse files
Login with NONLINEARIZABLE=1 for quicker auth
1 parent 2e259f1 commit 0922c14

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/drivers/utilities.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,17 @@ export function anonimizeError(error: Error): Error {
3636

3737
/** Initialization commands sent to database when connection is established */
3838
export function getInitializationCommands(config: SQLiteCloudConfig): string {
39-
// first user authentication, then all other commands
40-
let commands = ''
41-
42-
if (config.non_linearizable) {
43-
commands += 'SET CLIENT KEY NONLINEARIZABLE TO 1; '
44-
}
39+
// we check the credentials using non linearizable so we're quicker
40+
// then we bring back linearizability unless specified otherwise
41+
let commands = 'SET CLIENT KEY NONLINEARIZABLE TO 1; '
4542

43+
// first user authentication, then all other commands
4644
if (config.apikey) {
4745
commands += `AUTH APIKEY ${config.apikey}; `
4846
} else {
4947
commands += `AUTH USER ${config.username || ''} ${config.password_hashed ? 'HASH' : 'PASSWORD'} ${config.password || ''}; `
5048
}
5149

52-
if (config.database) {
53-
if (config.create && !config.memory) {
54-
commands += `CREATE DATABASE ${config.database} IF NOT EXISTS; `
55-
}
56-
commands += `USE DATABASE ${config.database}; `
57-
}
5850
if (config.compression) {
5951
commands += 'SET CLIENT KEY COMPRESSION TO 1; '
6052
}
@@ -74,6 +66,19 @@ export function getInitializationCommands(config: SQLiteCloudConfig): string {
7466
commands += `SET CLIENT KEY MAXROWSET TO ${config.maxrowset}; `
7567
}
7668

69+
// we ALWAYS set non linearizable to 1 when we start so we can be quicker on login
70+
// but then we need to put it back to its default value if "linearizable" unless set
71+
if (!config.non_linearizable) {
72+
commands += 'SET CLIENT KEY NONLINEARIZABLE TO 0; '
73+
}
74+
75+
if (config.database) {
76+
if (config.create && !config.memory) {
77+
commands += `CREATE DATABASE ${config.database} IF NOT EXISTS; `
78+
}
79+
commands += `USE DATABASE ${config.database}; `
80+
}
81+
7782
return commands
7883
}
7984

0 commit comments

Comments
 (0)