Remove ssb.messageContentGet. It's easy to do this with ssb.sqlAsync, and this wasn't being used productively. Three uses of DB on the main thread remaining.

This commit is contained in:
Cory McWilliams 2024-06-16 16:02:39 -04:00
parent 3eab5a5f70
commit dbe24494d9
2 changed files with 7 additions and 42 deletions

View File

@ -749,7 +749,7 @@ async function getProcessBlob(blobId, key, options) {
}; };
process.task.setImports(imports); process.task.setImports(imports);
process.task.activate(); process.task.activate();
let source = await getBlobOrContent(blobId); let source = await ssb.blobGet(blobId);
let appSourceName = blobId; let appSourceName = blobId;
let appSource = utf8Decode(source); let appSource = utf8Decode(source);
try { try {
@ -757,7 +757,7 @@ async function getProcessBlob(blobId, key, options) {
if (appObject.type == 'tildefriends-app') { if (appObject.type == 'tildefriends-app') {
appSourceName = options?.script ?? 'app.js'; appSourceName = options?.script ?? 'app.js';
let id = appObject.files[appSourceName]; let id = appObject.files[appSourceName];
let blob = await getBlobOrContent(id); let blob = await ssb.blobGet(id);
appSource = utf8Decode(blob); appSource = utf8Decode(blob);
await process.task.loadFile([ await process.task.loadFile([
'/tfrpc.js', '/tfrpc.js',
@ -767,7 +767,7 @@ async function getProcessBlob(blobId, key, options) {
Object.keys(appObject.files).map(async function (f) { Object.keys(appObject.files).map(async function (f) {
await process.task.loadFile([ await process.task.loadFile([
f, f,
await getBlobOrContent(appObject.files[f]), await ssb.blobGet(appObject.files[f]),
]); ]);
}) })
); );
@ -851,21 +851,6 @@ function sendData(response, data, type, headers, status_code) {
} }
} }
/**
* TODOC
* @param {*} id
* @returns
*/
async function getBlobOrContent(id) {
if (!id) {
return;
} else if (id.startsWith('&')) {
return ssb.blobGet(id);
} else if (id.startsWith('%')) {
return ssb.messageContentGet(id);
}
}
let g_handler_index = 0; let g_handler_index = 0;
/** /**
@ -993,7 +978,7 @@ async function blobHandler(request, response, blobId, uri) {
response.writeHead(304, headers); response.writeHead(304, headers);
response.end(); response.end();
} else { } else {
data = await getBlobOrContent(id); data = await ssb.blobGet(id);
if (match[3]) { if (match[3]) {
let appObject = JSON.parse(data); let appObject = JSON.parse(data);
data = appObject.files[match[3]]; data = appObject.files[match[3]];
@ -1025,7 +1010,7 @@ async function blobHandler(request, response, blobId, uri) {
response.writeHead(304, headers); response.writeHead(304, headers);
response.end(); response.end();
} else { } else {
data = await getBlobOrContent(blobId); data = await ssb.blobGet(blobId);
sendData( sendData(
response, response,
data, data,
@ -1141,7 +1126,7 @@ async function blobHandler(request, response, blobId, uri) {
app_id = await db.get('path:' + match[2]); app_id = await db.get('path:' + match[2]);
} }
let app_object = JSON.parse(utf8Decode(await getBlobOrContent(app_id))); let app_object = JSON.parse(utf8Decode(await ssb.blobGet(app_id)));
id = app_object?.files[uri.substring(1)]; id = app_object?.files[uri.substring(1)];
if (!id && app_object?.files['handler.js']) { if (!id && app_object?.files['handler.js']) {
let answer; let answer;
@ -1197,7 +1182,7 @@ async function blobHandler(request, response, blobId, uri) {
'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Origin': '*',
'Content-Security-Policy': k_content_security_policy, 'Content-Security-Policy': k_content_security_policy,
}; };
data = await getBlobOrContent(id); data = await ssb.blobGet(id);
let type = let type =
httpd.mime_type_from_extension(uri) || httpd.mime_type_from_extension(uri) ||
httpd.mime_type_from_magic_bytes(data); httpd.mime_type_from_magic_bytes(data);

View File

@ -910,25 +910,6 @@ static JSValue _tf_ssb_blobStore(JSContext* context, JSValueConst this_val, int
return result; return result;
} }
static JSValue _tf_ssb_messageContentGet(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{
JSValue result = JS_NULL;
tf_ssb_t* ssb = JS_GetOpaque(this_val, _tf_ssb_classId);
if (ssb)
{
const char* id = JS_ToCString(context, argv[0]);
uint8_t* blob = NULL;
size_t size = 0;
if (tf_ssb_db_message_content_get(ssb, id, &blob, &size))
{
result = JS_NewArrayBufferCopy(context, blob, size);
tf_free(blob);
}
JS_FreeCString(context, id);
}
return result;
}
static JSValue _tf_ssb_connections(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) static JSValue _tf_ssb_connections(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{ {
JSValue result = JS_NULL; JSValue result = JS_NULL;
@ -2156,7 +2137,6 @@ void tf_ssb_register(JSContext* context, tf_ssb_t* ssb)
JS_SetPropertyStr(context, object, "getActiveIdentity", JS_NewCFunction(context, _tf_ssb_getActiveIdentity, "getActiveIdentity", 3)); JS_SetPropertyStr(context, object, "getActiveIdentity", JS_NewCFunction(context, _tf_ssb_getActiveIdentity, "getActiveIdentity", 3));
JS_SetPropertyStr(context, object, "getIdentityInfo", JS_NewCFunction(context, _tf_ssb_getIdentityInfo, "getIdentityInfo", 3)); JS_SetPropertyStr(context, object, "getIdentityInfo", JS_NewCFunction(context, _tf_ssb_getIdentityInfo, "getIdentityInfo", 3));
JS_SetPropertyStr(context, object, "blobGet", JS_NewCFunction(context, _tf_ssb_blobGet, "blobGet", 1)); JS_SetPropertyStr(context, object, "blobGet", JS_NewCFunction(context, _tf_ssb_blobGet, "blobGet", 1));
JS_SetPropertyStr(context, object, "messageContentGet", JS_NewCFunction(context, _tf_ssb_messageContentGet, "messageContentGet", 1));
JS_SetPropertyStr(context, object, "connections", JS_NewCFunction(context, _tf_ssb_connections, "connections", 0)); JS_SetPropertyStr(context, object, "connections", JS_NewCFunction(context, _tf_ssb_connections, "connections", 0));
JS_SetPropertyStr(context, object, "storedConnections", JS_NewCFunction(context, _tf_ssb_storedConnections, "storedConnections", 0)); JS_SetPropertyStr(context, object, "storedConnections", JS_NewCFunction(context, _tf_ssb_storedConnections, "storedConnections", 0));
JS_SetPropertyStr(context, object, "getConnection", JS_NewCFunction(context, _tf_ssb_getConnection, "getConnection", 1)); JS_SetPropertyStr(context, object, "getConnection", JS_NewCFunction(context, _tf_ssb_getConnection, "getConnection", 1));