Matt
Matt
TTCTheo's Typesafe Cult
Created by tyler4949 on 1/13/2024 in #questions
Update local data from useQuery
as of now with the app arouter is it difficult to revalidate data iwth query keys?
8 replies
TTCTheo's Typesafe Cult
Created by Matt on 11/29/2023 in #questions
Google sheet api / scaleable api
how would you address it. pay people basically looks at a prisma row, sees if a inv column is null, if it is it pays it then fills that column. I have had 2 post requests come in at same time by one of the users on my crm and it sent 2 payments because of that slight second
41 replies
TTCTheo's Typesafe Cult
Created by Matt on 11/29/2023 in #questions
Google sheet api / scaleable api
so each one of these looks at a master sheet with like 3000 rows, finds the ceo, goes to their sheet with possibly thousands of rows and grabs all values, using js to finds a matching row, then updates that range specifically. Each function is updating a different sheet though. so none of these functions can step on each other toes. The issue arises when i send say 20 post requests at once to this function. The rows update in all different order. ill watch 7 rows pop up, and ill see a bunch of names flicker over the same rows. the missing 13
41 replies
TTCTheo's Typesafe Cult
Created by Matt on 11/29/2023 in #questions
Google sheet api / scaleable api
the googleSheetContact looks like this.
const a = await updateLeadCeo({
invoiceId: contact.mgt_inv,
contact,
sheets,
sheetId,
mgtName: contact.mgt_name,
amount: contact.mgt_amt,
});
array.push(a);
}
if (contact.fta_name) {
const a = await updateLeadCeo({
invoiceId: contact.fta_inv,
contact,
sheets,
sheetId,
mgtName: contact.fta_name,
amount: contact.fta_amt,
});
array.push(a);
}
if (contact.div_name) {
const a = await updateLeadCeo({
invoiceId: contact.div_inv,
contact,
sheets,
sheetId,
mgtName: contact.div_name,
amount: contact.div_amt,
});
array.push(a);
}
if (contact.fsl_name) {
const a = await updateLeadCeo({
invoiceId: contact.fsl_inv,
contact,
sheets,
sheetId,
mgtName: contact.fsl_name,
amount: contact.fsl_amt,
});
array.push(a);
}
const a = await updateLeadCeo({
invoiceId: contact.mgt_inv,
contact,
sheets,
sheetId,
mgtName: contact.mgt_name,
amount: contact.mgt_amt,
});
array.push(a);
}
if (contact.fta_name) {
const a = await updateLeadCeo({
invoiceId: contact.fta_inv,
contact,
sheets,
sheetId,
mgtName: contact.fta_name,
amount: contact.fta_amt,
});
array.push(a);
}
if (contact.div_name) {
const a = await updateLeadCeo({
invoiceId: contact.div_inv,
contact,
sheets,
sheetId,
mgtName: contact.div_name,
amount: contact.div_amt,
});
array.push(a);
}
if (contact.fsl_name) {
const a = await updateLeadCeo({
invoiceId: contact.fsl_inv,
contact,
sheets,
sheetId,
mgtName: contact.fsl_name,
amount: contact.fsl_amt,
});
array.push(a);
}
41 replies
TTCTheo's Typesafe Cult
Created by Matt on 11/29/2023 in #questions
Google sheet api / scaleable api
nah that function hasnt given me issues in a month. once it double paid but i think that cheeky timeout might have avoided that
41 replies
TTCTheo's Typesafe Cult
Created by Matt on 11/29/2023 in #questions
Google sheet api / scaleable api
paypeople probably gonna do like 40 prisma db updates and a few api post requests
41 replies
TTCTheo's Typesafe Cult
Created by Matt on 11/29/2023 in #questions
Google sheet api / scaleable api
thank you
41 replies
TTCTheo's Typesafe Cult
Created by Matt on 11/29/2023 in #questions
Google sheet api / scaleable api
beuatiful
41 replies
TTCTheo's Typesafe Cult
Created by Matt on 11/29/2023 in #questions
Google sheet api / scaleable api
const mutex = new Mutex();

const ratelimit = new Ratelimit({
redis: Redis.fromEnv(),
limiter: Ratelimit.slidingWindow(5, "60 s"),
analytics: true,
});
const c = new Client({
token: process.env.QSTASH_TOKEN!,
});
export const contactUpsertRouter = createTRPCRouter({
hello: publicProcedure
.meta({ openapi: { method: "POST", path: "/lead-update" } })

.input(crmSchema)
.output(z.object({ greeting: z.string() }))
.query(async ({ input, ctx }) => {
const delayMilliseconds = Math.floor(Math.random() * 5000); // Adjust the range as needed

let contact = await parseContact(input, ctx.db);

// i made it do this to in case payPeople needs more updated values ran into double payment once or twice
try {
await new Promise((resolve) => setTimeout(resolve, delayMilliseconds));
contact = await parseContact(input, ctx.db);
} catch (error) {
console.error(error);
}
if (contact) {
const release = await mutex.acquire();
await payPeople({ leadRow: contact, db: ctx.db });

const { success } = await ratelimit.blockUntilReady("ok", 60_000);

if (!success) {
console.log("error");
}
await googleSheetContact({ contact: contact });
release();
}

return {
greeting: Hello ,
};
}),
const mutex = new Mutex();

const ratelimit = new Ratelimit({
redis: Redis.fromEnv(),
limiter: Ratelimit.slidingWindow(5, "60 s"),
analytics: true,
});
const c = new Client({
token: process.env.QSTASH_TOKEN!,
});
export const contactUpsertRouter = createTRPCRouter({
hello: publicProcedure
.meta({ openapi: { method: "POST", path: "/lead-update" } })

.input(crmSchema)
.output(z.object({ greeting: z.string() }))
.query(async ({ input, ctx }) => {
const delayMilliseconds = Math.floor(Math.random() * 5000); // Adjust the range as needed

let contact = await parseContact(input, ctx.db);

// i made it do this to in case payPeople needs more updated values ran into double payment once or twice
try {
await new Promise((resolve) => setTimeout(resolve, delayMilliseconds));
contact = await parseContact(input, ctx.db);
} catch (error) {
console.error(error);
}
if (contact) {
const release = await mutex.acquire();
await payPeople({ leadRow: contact, db: ctx.db });

const { success } = await ratelimit.blockUntilReady("ok", 60_000);

if (!success) {
console.log("error");
}
await googleSheetContact({ contact: contact });
release();
}

return {
greeting: Hello ,
};
}),
41 replies
TTCTheo's Typesafe Cult
Created by Matt on 11/29/2023 in #questions
Google sheet api / scaleable api
how did u get coloring?
41 replies
TTCTheo's Typesafe Cult
Created by Matt on 11/29/2023 in #questions
Google sheet api / scaleable api
so wtf is mutex even doing, why do i like it lol
41 replies
TTCTheo's Typesafe Cult
Created by Matt on 11/29/2023 in #questions
Google sheet api / scaleable api
ahh nice
41 replies
TTCTheo's Typesafe Cult
Created by Matt on 11/29/2023 in #questions
Google sheet api / scaleable api
const mutex = new Mutex(); const ratelimit = new Ratelimit({ redis: Redis.fromEnv(), limiter: Ratelimit.slidingWindow(5, "60 s"), analytics: true, }); const c = new Client({ token: process.env.QSTASH_TOKEN!, }); export const contactUpsertRouter = createTRPCRouter({ hello: publicProcedure .meta({ openapi: { method: "POST", path: "/lead-update" } }) .input(crmSchema) .output(z.object({ greeting: z.string() })) .query(async ({ input, ctx }) => { const delayMilliseconds = Math.floor(Math.random() * 5000); // Adjust the range as needed let contact = await parseContact(input, ctx.db); // i made it do this to in case payPeople needs more updated values ran into double payment once or twice try { await new Promise((resolve) => setTimeout(resolve, delayMilliseconds)); contact = await parseContact(input, ctx.db); } catch (error) { console.error(error); } if (contact) { const release = await mutex.acquire(); await payPeople({ leadRow: contact, db: ctx.db }); const { success } = await ratelimit.blockUntilReady("ok", 60_000); if (!success) { console.log("error"); } await googleSheetContact({ contact: contact }); release(); } return { greeting: Hello , }; }), please dont laugh too hard
41 replies
TTCTheo's Typesafe Cult
Created by Matt on 11/29/2023 in #questions
Google sheet api / scaleable api
i tihnk i have that
41 replies
TTCTheo's Typesafe Cult
Created by Matt on 11/29/2023 in #questions
Google sheet api / scaleable api
https://srijancse.medium.com/how-real-time-collaborative-editing-work-operational-transformation-ac4902d75682 Bro what is this? This is a blanket theory that i can learn and use to lots of different things that cause problems like im running into. I need to code this into my nodejs serverless function?
41 replies
TTCTheo's Typesafe Cult
Created by Matt on 11/29/2023 in #questions
Google sheet api / scaleable api
const res = await sheets.spreadsheets.values.get({ spreadsheetId: sheetId, range: range, }); like if this query could provide a code that locks all other querys unless you use that code so that my update goes through on the correct index
41 replies
TTCTheo's Typesafe Cult
Created by Matt on 11/29/2023 in #questions
Google sheet api / scaleable api
is that the best way to do it. i dont have to change the way im doing querys with google sheets i need to like gate the entire api handler or something? Is there a way to add into my query for google sheets to lock it until my next query. Im doing alot of this.
//usees reads / writes
const rows = await getRowValues({
sheets,
sheetId: sheetId,
range: "Sheet1",
});
// js only
const { foundRowIndex, foundRow } = findRow({
fullName: mgtName,
phone: null,
rows,
});

if (
foundRow &&
typeof foundRow[3] === "string" &&
typeof foundRow[6] === "string"
) {
const sheetIdReturn: string = foundRow[3];
const range = `${foundRow[6]}!Ax:Ox`;
if (sheetIdReturn && range) {
// only updates row at sheet id and range. either uses foundrowIndex or rowvalues.length+1
const a = await addUpdateLead({
contact,
sheets,
sheetId: sheetIdReturn,
range: range,
values: values,
});
//usees reads / writes
const rows = await getRowValues({
sheets,
sheetId: sheetId,
range: "Sheet1",
});
// js only
const { foundRowIndex, foundRow } = findRow({
fullName: mgtName,
phone: null,
rows,
});

if (
foundRow &&
typeof foundRow[3] === "string" &&
typeof foundRow[6] === "string"
) {
const sheetIdReturn: string = foundRow[3];
const range = `${foundRow[6]}!Ax:Ox`;
if (sheetIdReturn && range) {
// only updates row at sheet id and range. either uses foundrowIndex or rowvalues.length+1
const a = await addUpdateLead({
contact,
sheets,
sheetId: sheetIdReturn,
range: range,
values: values,
});
41 replies
TTCTheo's Typesafe Cult
Created by Matt on 11/29/2023 in #questions
Google sheet api / scaleable api
YES
41 replies
TTCTheo's Typesafe Cult
Created by Matt on 11/29/2023 in #questions
Google sheet api / scaleable api
its honestly pretty fucking werid but i can explain it in 30 seconds. theres like 4 sheets that get looked up and i can make one function taht looks up all 4 instead of like 16
41 replies
TTCTheo's Typesafe Cult
Created by Matt on 11/29/2023 in #questions
Google sheet api / scaleable api
can i call you
41 replies