Skip to content

Commit 515bf72

Browse files
committed
Major performance boost for fetching schemas
Signed-off-by: worksofliam <[email protected]>
1 parent 3225560 commit 515bf72

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/connection/manager.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,17 @@ export class SQLJobManager {
119119
// 2147483647 is NOT arbitrary. On the server side, this is processed as a Java
120120
// int. This is the largest number available without overflow (Integer.MAX_VALUE)
121121

122+
// const s = performance.now()
123+
// console.log(`Running statement: ${query.padEnd(40).substring(0, 40)}`);
124+
122125
const statement = await this.getPagingStatement<T>(query, opts);
123126
const results = await statement.execute(rowsToFetch);
124127
statement.close();
128+
129+
// const e = performance.now()
130+
// console.log(`Statement executed in ${e - s} ms. ${results.data.length} rows returned.`);
131+
// console.log(`\t${query.padEnd(40).substring(0, 40)}`)
132+
125133
return results.data;
126134
}
127135

src/database/schemas.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,11 @@ export default class Schemas {
207207
case `schemas`:
208208
selects.push(
209209
[
210-
`select '${type}' as OBJ_TYPE, '' as TABLE_TYPE, SCHEMA_NAME as NAME, SCHEMA_TEXT as TEXT, SYSTEM_SCHEMA_NAME as SYS_NAME, '' as SYS_SCHEMA, '' as SPECNAME, '' as BASE_SCHEMA, '' as BASE_OBJ`,
211-
`from QSYS2.SYSSCHEMAS`,
210+
``,
211+
`SELECT '${type}' as OBJ_TYPE, '' as TABLE_TYPE, OBJLONGNAME AS NAME, '' as TEXT, OBJNAME AS SYS_NAME, '' as SYS_SCHEMA, '' as SPECNAME, '' as BASE_SCHEMA, '' as BASE_OBJ`,
212+
`FROM TABLE(QSYS2.OBJECT_STATISTICS('*ALLSIMPLE', 'LIB')) Z`,
212213
details.filter
213-
? `where UPPER(SCHEMA_NAME) = ? or UPPER(SYSTEM_SCHEMA_NAME) = ?`
214+
? `where UPPER(OBJLONGNAME) = ? or UPPER(OBJNAME) = ?`
214215
: ``,
215216
].join(` `)
216217
);

src/language/providers/completionProvider.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,11 @@ async function getCompletionItemsForRefs(currentStatement: LanguageStatement.def
331331

332332
const curClause = currentStatement.getClauseForOffset(offset);
333333
const tokenAtOffset = currentStatement.getTokenByOffset(offset);
334-
334+
335+
// Get all the schemas
336+
if (objectRefs.length === 0 && cteList.length === 0) {
337+
completionItems.push(...(await getCachedSchemas()));
338+
}
335339
// Set the default schema for all references without one
336340
for (let ref of objectRefs) {
337341
if (!ref.object.schema) {
@@ -430,12 +434,6 @@ async function getCompletionItemsForRefs(currentStatement: LanguageStatement.def
430434
}
431435
}
432436

433-
if (completionItems.length === 0) {
434-
// Get all the schemas
435-
// TODO: very very slow
436-
// completionItems.push(...(await getCachedSchemas()));
437-
}
438-
439437
return completionItems;
440438
}
441439

0 commit comments

Comments
 (0)