forked from cory/tildefriends
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:
parent
3eab5a5f70
commit
dbe24494d9
29
core/core.js
29
core/core.js
@ -749,7 +749,7 @@ async function getProcessBlob(blobId, key, options) {
|
||||
};
|
||||
process.task.setImports(imports);
|
||||
process.task.activate();
|
||||
let source = await getBlobOrContent(blobId);
|
||||
let source = await ssb.blobGet(blobId);
|
||||
let appSourceName = blobId;
|
||||
let appSource = utf8Decode(source);
|
||||
try {
|
||||
@ -757,7 +757,7 @@ async function getProcessBlob(blobId, key, options) {
|
||||
if (appObject.type == 'tildefriends-app') {
|
||||
appSourceName = options?.script ?? 'app.js';
|
||||
let id = appObject.files[appSourceName];
|
||||
let blob = await getBlobOrContent(id);
|
||||
let blob = await ssb.blobGet(id);
|
||||
appSource = utf8Decode(blob);
|
||||
await process.task.loadFile([
|
||||
'/tfrpc.js',
|
||||
@ -767,7 +767,7 @@ async function getProcessBlob(blobId, key, options) {
|
||||
Object.keys(appObject.files).map(async function (f) {
|
||||
await process.task.loadFile([
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -993,7 +978,7 @@ async function blobHandler(request, response, blobId, uri) {
|
||||
response.writeHead(304, headers);
|
||||
response.end();
|
||||
} else {
|
||||
data = await getBlobOrContent(id);
|
||||
data = await ssb.blobGet(id);
|
||||
if (match[3]) {
|
||||
let appObject = JSON.parse(data);
|
||||
data = appObject.files[match[3]];
|
||||
@ -1025,7 +1010,7 @@ async function blobHandler(request, response, blobId, uri) {
|
||||
response.writeHead(304, headers);
|
||||
response.end();
|
||||
} else {
|
||||
data = await getBlobOrContent(blobId);
|
||||
data = await ssb.blobGet(blobId);
|
||||
sendData(
|
||||
response,
|
||||
data,
|
||||
@ -1141,7 +1126,7 @@ async function blobHandler(request, response, blobId, uri) {
|
||||
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)];
|
||||
if (!id && app_object?.files['handler.js']) {
|
||||
let answer;
|
||||
@ -1197,7 +1182,7 @@ async function blobHandler(request, response, blobId, uri) {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Content-Security-Policy': k_content_security_policy,
|
||||
};
|
||||
data = await getBlobOrContent(id);
|
||||
data = await ssb.blobGet(id);
|
||||
let type =
|
||||
httpd.mime_type_from_extension(uri) ||
|
||||
httpd.mime_type_from_magic_bytes(data);
|
||||
|
20
src/ssb.js.c
20
src/ssb.js.c
@ -910,25 +910,6 @@ static JSValue _tf_ssb_blobStore(JSContext* context, JSValueConst this_val, int
|
||||
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)
|
||||
{
|
||||
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, "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, "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, "storedConnections", JS_NewCFunction(context, _tf_ssb_storedConnections, "storedConnections", 0));
|
||||
JS_SetPropertyStr(context, object, "getConnection", JS_NewCFunction(context, _tf_ssb_getConnection, "getConnection", 1));
|
||||
|
Loading…
Reference in New Issue
Block a user