Skip to content

Commit

Permalink
Cache db
Browse files Browse the repository at this point in the history
  • Loading branch information
jalvarado91 committed Mar 19, 2024
1 parent bd965d4 commit f282450
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/client/EpisodesScreen/EpisodeModalSheet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function EpisodeTracksList({ episodeId }: { episodeId: string }) {

const currentTrack = possibleTracks.at(-1);

function onTrckClick(t: EpisodeTrackProjection) {
function onTrackClick(t: EpisodeTrackProjection) {
if (t.timestamp) {
playerActions.setCuePosition(t.timestamp * 1000);
}
Expand All @@ -158,7 +158,7 @@ function EpisodeTracksList({ episodeId }: { episodeId: string }) {
const isCurrent = currentTrack?.order === t.order;
return (
<button
onClick={() => onTrckClick(t)}
onClick={() => onTrackClick(t)}
className={cn("w-full relative")}
>
<div
Expand Down
9 changes: 8 additions & 1 deletion src/server/db.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { MongoClient } from "mongodb";
import { Db, MongoClient } from "mongodb";

const connectionString =
process.env.MONGO_CONNECTION_STRING || "noconnectionstringpassed";

const dbName = "soulector";

let cachedClient: Db;

export async function createDbConnection() {
if (cachedClient) {
return cachedClient;
}

const client = new MongoClient(connectionString);
await client.connect();
const db = client.db(dbName);
cachedClient = db;
return db;
}
2 changes: 1 addition & 1 deletion src/server/update-episode-details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export async function updateEpisodeDetails(
);

if (updated.modifiedCount < 1) {
console.log("no updates happened. Sad");
console.log("no updates happened. Sad", updatedEpisode);
}

console.log("updated result", updated);
Expand Down

1 comment on commit f282450

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for soulector ready!

✅ Preview
https://soulector-qu46a4c4j-jalvarado91.vercel.app

Built with commit f282450.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.