fix(elasticsearch): complete mapping fields in Query DSL field slots
This commit is contained in:
1 parent
dd84e6c06a
commit
c0d6965b5f
5 files changed
+628
-58
No files matched your search
@@ -138,6 +138,7 @@ import { useSavedSqlStore } from "@/stores/savedSqlStore";
|
||||
import { decorateDatabaseSavedSqlTreeNodes, indexSavedSqlFilesByDatabase, stripDatabaseSavedSqlTreeNodes, withDatabaseSavedSqlRoot } from "@/lib/savedSql/savedSqlDatabaseTree";
|
||||
import { encodeSqlServerLinkedSchema, parseSqlServerLinkedSchema } from "@/lib/database/sqlServerLinkedServers";
|
||||
import { inferMongoCompletionFields, type MongoCompletionField } from "@/lib/mongo/mongoCompletion";
|
||||
import { flattenElasticsearchMappingFields, type ElasticsearchCompletionField } from "@/lib/elasticsearch/elasticsearchCompletion";
|
||||
import { isMongoLegacyDriverProfile } from "@/lib/mongo/mongoCapabilities";
|
||||
import { mongoCollectionKindFromNode, toMongoCollectionKind, visibleMongoCollections } from "@/lib/sidebar/mongoCollectionMutation";
|
||||
import { completionSchemasFromTree, completionTablesFromTree } from "@/lib/metadata/completionTreeIndex";
|
||||
@@ -486,6 +487,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
const primaryVisibleObjectNames = ref<Record<string, string[]>>({});
|
||||
const sqlServerCompletionContextCache = ref<Record<string, SqlServerCompletionContext>>({});
|
||||
const elasticsearchCompletionIndicesCache = ref<Record<string, string[]>>({});
|
||||
const elasticsearchCompletionFieldsCache = ref<Record<string, ElasticsearchCompletionField[]>>({});
|
||||
const redisCompletionKeysCache = ref<Record<string, string[]>>({});
|
||||
const redisCommandDocsCache = ref<Record<string, RedisCommandDocumentation[]>>({});
|
||||
const redisCommandDocsCacheGeneration = new Map<string, number>();
|
||||
@@ -3511,6 +3513,9 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
for (const key of Object.keys(elasticsearchCompletionIndicesCache.value)) {
|
||||
if (key === exactCacheKey || key.startsWith(cachePrefix)) delete elasticsearchCompletionIndicesCache.value[key];
|
||||
}
|
||||
for (const key of Object.keys(elasticsearchCompletionFieldsCache.value)) {
|
||||
if (key === exactCacheKey || key.startsWith(cachePrefix)) delete elasticsearchCompletionFieldsCache.value[key];
|
||||
}
|
||||
for (const key of Object.keys(redisCompletionKeysCache.value)) {
|
||||
if (key === exactCacheKey || key.startsWith(cachePrefix)) delete redisCompletionKeysCache.value[key];
|
||||
}
|
||||
@@ -7975,6 +7980,21 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
return elasticsearchCompletionIndicesCache.value[cacheKey];
|
||||
}
|
||||
|
||||
async function listElasticsearchCompletionFields(connectionId: string, index: string): Promise<ElasticsearchCompletionField[]> {
|
||||
if (!index) return [];
|
||||
const cacheKey = `${connectionId}:${index}`;
|
||||
const cached = elasticsearchCompletionFieldsCache.value[cacheKey];
|
||||
if (cached) return cached;
|
||||
return withCompletionInFlight(`${cacheKey}:es-fields`, async () => {
|
||||
await ensureConnected(connectionId);
|
||||
const mapping = await api.elasticsearchGetIndexMetadata(connectionId, index, "mapping");
|
||||
const fields = flattenElasticsearchMappingFields(mapping);
|
||||
elasticsearchCompletionFieldsCache.value[cacheKey] = fields;
|
||||
evictOldestCacheEntries(elasticsearchCompletionFieldsCache.value, COMPLETION_CACHE_MAX);
|
||||
return fields;
|
||||
});
|
||||
}
|
||||
|
||||
// Upper bound on cached key names per db, to keep completion memory bounded
|
||||
// (Redis can hold far more keys than we ever want resident for autocomplete).
|
||||
const REDIS_COMPLETION_KEYS_MAX = 1000;
|
||||
@@ -9388,6 +9408,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
refreshCompletionSchemas,
|
||||
refreshCompletionDatabases,
|
||||
listElasticsearchCompletionIndices,
|
||||
listElasticsearchCompletionFields,
|
||||
listRedisCompletionKeys,
|
||||
listRedisCompletionCommandDocs,
|
||||
listMongoCompletionCollections,
|
||||
|
||||
Reference in new issue
Block a user