Skip to content

Commit 68b1ad8

Browse files
committed
remove options and some redis caching
1 parent 77ffe0a commit 68b1ad8

File tree

7 files changed

+43
-71
lines changed

7 files changed

+43
-71
lines changed

features/cache/index.ts

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
import { REDIS_CACHE_DB } from "@/lib/constants"
1+
import { REDIS_CACHE_DB } from "@/lib/constants";
2+
import { ValueType } from "ioredis";
3+
import { getRedisClient } from "@/lib/redis";
24
import { isUndefined } from "lodash";
3-
import Redis, { ValueType } from "ioredis";
45

56
class CacheDriver {
67
public redis;
78

8-
constructor({ url }: { url: string }) {
9-
const options = {
10-
keyPrefix: `basetool_${process.env.NEXT_PUBLIC_APP_ENV}:`,
11-
lazyConnect: true,
12-
db: REDIS_CACHE_DB,
13-
};
14-
this.redis = new Redis(url, options);
9+
constructor() {
10+
this.redis = getRedisClient(REDIS_CACHE_DB);
1511
}
1612

1713
public async get(key: string): Promise<string | null> {
@@ -65,16 +61,21 @@ class CacheDriver {
6561

6662
// Store the result
6763
if (!isUndefined(options.expiresIn)) {
68-
await this.set({ key, value: JSON.stringify(result), time: options.expiresIn, expiryMode: 'EX' });
69-
} else{
70-
await this.set({ key, value: JSON.stringify(result)});
64+
await this.set({
65+
key,
66+
value: JSON.stringify(result),
67+
time: options.expiresIn,
68+
expiryMode: "EX",
69+
});
70+
} else {
71+
await this.set({ key, value: JSON.stringify(result) });
7172
}
7273

7374
// Return the result
7475
return result;
7576
}
7677
}
7778

78-
const cache = new CacheDriver({ url: process.env.REDIS_URL as string });
79+
const cache = new CacheDriver();
7980

8081
export default cache;

features/data-sources/components/DataSourceTileCreate.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ const DataSourceTileCreate = ({
7878
className="w-5 h-5"
7979
checked={!comingSoon && id === dataSourceId}
8080
disabled={comingSoon}
81+
onChange={() => ''}
8182
/>
8283
</div>
8384
<div className="relative h-12 mb-4">

features/options/index.ts

+10-42
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,13 @@
1-
import { REDIS_OPTIONS_DB } from "@/lib/constants";
2-
import { isUndefined } from "lodash";
3-
import Redis, { ValueType } from "ioredis";
1+
type PossibleValues = string | boolean | number | null | undefined;
42

5-
class Options {
6-
public redis;
3+
const OPTIONS: Record<string, PossibleValues> = {
4+
runInProxy: false,
5+
};
76

8-
constructor({ url }: { url: string }) {
9-
const options = {
10-
keyPrefix: `basetool_${process.env.NEXT_PUBLIC_APP_ENV}:`,
11-
lazyConnect: true,
12-
db: REDIS_OPTIONS_DB,
13-
};
14-
this.redis = new Redis(url, options);
15-
}
7+
const optionsHandler = {
8+
get: async (key: string): Promise<PossibleValues> => {
9+
return OPTIONS[key];
10+
},
11+
};
1612

17-
public async get(key: string): Promise<string | null> {
18-
return await this.redis.get(key);
19-
}
20-
21-
public async exists(key: string): Promise<boolean> {
22-
return (await this.redis.exists(key)) !== 0;
23-
}
24-
25-
public async set(
26-
key: string,
27-
value: ValueType,
28-
options: {
29-
expiryMode?: "EX";
30-
time?: number;
31-
} = {
32-
expiryMode: "EX",
33-
}
34-
) {
35-
if (!isUndefined(options.time)) {
36-
return this.redis.set(key, value, options.expiryMode, options.time);
37-
}
38-
39-
return this.redis.set(key, value);
40-
}
41-
}
42-
43-
const options = new Options({ url: process.env.REDIS_URL as string });
44-
45-
export default options;
13+
export default optionsHandler;

lib/redis.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Redis from "ioredis";
2+
3+
const getRedisClient = (db: number) => {
4+
const options = {
5+
keyPrefix: `basetool_${process.env.NEXT_PUBLIC_APP_ENV}:`,
6+
lazyConnect: true,
7+
db,
8+
};
9+
const client = new Redis(process.env.REDIS_URL, options);
10+
11+
return client;
12+
};
13+
14+
export { getRedisClient };

pages/data-sources/new.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ function New() {
4646
{availableDataSources.map(
4747
({ id, label, beta, comingSoon, readOnly }) => (
4848
<DataSourceTileCreate
49+
key={id}
4950
id={id}
5051
label={label}
5152
beta={beta}

plugins/data-sources/QueryServiceWrapper.ts

+2-15
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default class QueryServiceWrapper implements IQueryServiceWrapper {
8686
}
8787

8888
public async disconnect() {
89-
return await this.queryService.disconnect()
89+
return await this.queryService.disconnect();
9090
}
9191
}
9292

@@ -163,20 +163,7 @@ export const runInSSHTunnel = async ({
163163
* Fetches and caches the key from S3
164164
*/
165165
const getSSHKey = async (Key: string) => {
166-
// Cache the key for 15 minutes so we avoid the S3 transport time.
167-
const stringifiedKey = await cache.fetch<string>({
168-
key: `ssh_key:${Key}`,
169-
options: {
170-
expiresIn: 900, // 15 minutes
171-
},
172-
callback: async () => {
173-
const key = await fetchKeyFromS3(Key);
174-
175-
return encrypt(key?.toString() as string);
176-
},
177-
});
178-
179-
return decrypt(stringifiedKey);
166+
return await fetchKeyFromS3(Key);
180167
};
181168

182169
/**

plugins/data-sources/serverHelpers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const runQueries = async (
4444
// We want to better control if the queries should run in a proxy
4545
// We're checking to see if the redis DB has any options set 1 or 0.
4646
// If nothing is set in redis, we're going to fallback to an environment variable.
47-
const runInProxyOverride = (await options.exists("runInProxy"))
47+
const runInProxyOverride = (await options.get("runInProxy"))
4848
? (await options.get("runInProxy")) === "1"
4949
: process.env.USE_PROXY === "1";
5050

0 commit comments

Comments
 (0)