Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid storing local blob urls in the cache #7062

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1179,10 +1179,12 @@ export class CommunityClient extends CandidService {
: dataClient.uploadData(event.event.content, [chatId.communityId]);

return uploadContentPromise.then((content) => {
const newContent = content ?? event.event.content;
if (content !== undefined) {
event.event.content = content;
}
const args = {
channel_id: BigInt(chatId.channelId),
content: apiMessageContent(newContent),
content: apiMessageContent(event.event.content),
message_id: event.event.messageId,
sender_name: senderName,
sender_display_name: senderDisplayName,
Expand All @@ -1207,10 +1209,7 @@ export class CommunityClient extends CandidService {
onRequestAccepted,
)
.then((resp) => {
const retVal: [SendMessageResponse, Message] = [
resp,
{ ...event.event, content: newContent },
];
const retVal: [SendMessageResponse, Message] = [resp, event.event];
setCachedMessageFromSendResponse(
this.db,
chatId,
Expand Down
11 changes: 5 additions & 6 deletions frontend/openchat-agent/src/services/group/group.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,11 @@ export class GroupClient extends CandidService {
: dataClient.uploadData(event.event.content, [this.chatId.groupId]);

return uploadContentPromise.then((content) => {
const newContent = content ?? event.event.content;
if (content !== undefined) {
event.event.content = content;
}
const args = {
content: apiMessageContent(newContent),
content: apiMessageContent(event.event.content),
message_id: event.event.messageId,
sender_name: senderName,
sender_display_name: senderDisplayName,
Expand All @@ -624,10 +626,7 @@ export class GroupClient extends CandidService {
onRequestAccepted,
)
.then((resp) => {
const retVal: [SendMessageResponse, Message] = [
resp,
{ ...event.event, content: newContent },
];
const retVal: [SendMessageResponse, Message] = [resp, event.event];
setCachedMessageFromSendResponse(
this.db,
this.chatId,
Expand Down
8 changes: 5 additions & 3 deletions frontend/openchat-agent/src/services/user/user.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,9 +767,11 @@ export class UserClient extends CandidService {
: dataClient.uploadData(event.event.content, [this.userId, chatId.userId]);

return uploadContentPromise.then((content) => {
const newContent = content ?? event.event.content;
if (content !== undefined) {
event.event.content = content;
}
const req = {
content: apiMessageContent(newContent),
content: apiMessageContent(event.event.content),
recipient: principalStringToBytes(chatId.userId),
message_id: event.event.messageId,
replies_to: mapOptional(event.event.repliesTo, (replyContext) =>
Expand All @@ -789,7 +791,7 @@ export class UserClient extends CandidService {
UserSendMessageArgs,
UserSendMessageResponse,
onRequestAccepted,
).then((resp) => [resp, { ...event.event, content: newContent }]);
).then((resp) => [resp, event.event]);
});
}

Expand Down
11 changes: 10 additions & 1 deletion frontend/openchat-agent/src/utils/caching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import type { CryptocurrencyContent } from "openchat-shared";
import type { PrizeContent } from "openchat-shared";
import type { P2PSwapContent } from "openchat-shared";

const CACHE_VERSION = 120;
const CACHE_VERSION = 121;
const EARLIEST_SUPPORTED_MIGRATION = 115;
const MAX_INDEX = 9999999999;

Expand Down Expand Up @@ -208,6 +208,14 @@ async function clearEverything(
nuke(db);
}

async function clearEvents(
_db: IDBPDatabase<ChatSchema>,
_principal: Principal,
tx: IDBPTransaction<ChatSchema, StoreNames<ChatSchema>[], "versionchange">,
) {
await tx.objectStore("chat_events").clear();
}

async function clearChatAndGroups(
_db: IDBPDatabase<ChatSchema>,
_principal: Principal,
Expand Down Expand Up @@ -247,6 +255,7 @@ const migrations: Record<number, MigrationFunction<ChatSchema>> = {
createBotsStore(db, principal, tx),
]);
},
121: clearEvents,
};

async function migrate(
Expand Down
Loading