Skip to content

Commit

Permalink
Merge pull request #1918 from compdemocracy/te-cache-bust
Browse files Browse the repository at this point in the history
add cachebust param
  • Loading branch information
colinmegill authored Feb 12, 2025
2 parents 2ba74b5 + fc823a1 commit 8fdfec5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
8 changes: 7 additions & 1 deletion client-report/src/components/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ const App = (props) => {
? window.location.search.split("model=")[1]?.split("&")[0]
: "openai"
);
const [searchParamsCache, setSearchParamCache] = useState(
window.location.search.includes("noCache=")
? window.location.search.split("noCache=")[1]?.split("&")[0]
: "false"
);

let corMatRetries;

Expand All @@ -101,6 +106,7 @@ const App = (props) => {
const urlParams = new URLSearchParams(queryString);
if (urlParams.get("section")) setSearchParamsSection(urlParams.get("section"));
if (urlParams.get("model")) setSearchParamModel(urlParams.get("model"));
if (urlParams.get("noCache")) setSearchParamCache(urlParams.get("noCache"));
}, [window.location?.pathname, window.location?.search]);

useEffect(() => {
Expand Down Expand Up @@ -173,7 +179,7 @@ const App = (props) => {
const response = await fetch(
`${urlPrefix}api/v3/reportNarrative?report_id=${report_id}${
searchParamsSection ? `&section=${searchParamsSection}` : ``
}${searchParamsModel ? `&model=${searchParamsModel}` : ``}`,
}${searchParamsModel ? `&model=${searchParamsModel}` : ``}${searchParamsCache ? `&noCache=${searchParamsCache}` : ``}`,
{
credentials: "include",
method: "get",
Expand Down
6 changes: 4 additions & 2 deletions server/src/routes/reportNarrative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,9 @@ export async function handle_GET_topics(
"polis-comments-and-group-demographics",
json
);
res.write(`POLIS-PING: calling topic timeout`);
setTimeout(async () => {
console.log("CALLING TOPIC");
res.write(`POLIS-PING: calling topic`);
const resp = await getModelResponse(
model,
system_lore,
Expand Down Expand Up @@ -708,7 +709,8 @@ export async function handle_GET_reportNarrative(
if (process.env.AWS_REGION && process.env.AWS_REGION?.trim().length > 0) {
storage = new DynamoStorageService(
process.env.AWS_REGION,
"report_narrative_store"
"report_narrative_store",
req.query.noCache === "true",
);
}
const modelParam = req.query.model || "openai";
Expand Down
8 changes: 7 additions & 1 deletion server/src/utils/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import {
export default class DynamoStorageService {
private client: DynamoDBClient;
private tableName: string;
private cacheDisabled: boolean;

constructor(region: string, tableName: string) {
constructor(region: string, tableName: string, disableCache?: boolean) {
const dynamoClient = new DynamoDBClient({ region });
this.client = dynamoClient;
this.tableName = tableName;
this.cacheDisabled = disableCache || false;
}

async putItem(item: Record<string, unknown> | undefined) {
Expand Down Expand Up @@ -42,6 +44,10 @@ export default class DynamoStorageService {
};

const command = new QueryCommand(params);

if (this.cacheDisabled) {
return []
}

try {
const data = await this.client.send(command);
Expand Down

0 comments on commit 8fdfec5

Please sign in to comment.