Skip to content

Commit

Permalink
dev: no icons form /whoami calls without icon_size
Browse files Browse the repository at this point in the history
Calls to `/whoami` generally don't require app icons. Fetching icons of
the smallest size still incurs round-trip latency from the database and
S3, as well as additional delay for any retries due to failed icon
generation.

Although this is technically a regression in `/whoami`, the impact is
localized to Puter's desktop only because apps are not allowed to
receive taskbar icons.
  • Loading branch information
KernelDeimos committed Dec 23, 2024
1 parent d1bec45 commit cb2653b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
53 changes: 29 additions & 24 deletions src/backend/src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,7 @@ async function suggest_app_for_fsentry(fsentry, options){
});
}

async function get_taskbar_items(user, { icon_size } = {}) {
async function get_taskbar_items(user, { icon_size, no_icons } = {}) {
/** @type BaseDatabaseAccessService */
const db = services.get('database').get(DB_WRITE, 'filesystem');

Expand Down Expand Up @@ -1499,26 +1499,31 @@ async function get_taskbar_items(user, { icon_size } = {}) {
let taskbar_items = [];
for (let index = 0; index < taskbar_items_from_db.length; index++) {
const taskbar_item_from_db = taskbar_items_from_db[index];
if(taskbar_item_from_db.type === 'app' && taskbar_item_from_db.name !== 'explorer'){
let item = {};
if(taskbar_item_from_db.name)
item = await get_app({name: taskbar_item_from_db.name});
else if(taskbar_item_from_db.id)
item = await get_app({id: taskbar_item_from_db.id});
else if(taskbar_item_from_db.uid)
item = await get_app({uid: taskbar_item_from_db.uid});

// if item not found, skip it
if(!item) continue;

// delete sensitive attributes
delete item.id;
delete item.owner_user_id;
delete item.timestamp;
// delete item.godmode;
delete item.approved_for_listing;
delete item.approved_for_opening_items;

if ( taskbar_item_from_db.type !== 'app' ) continue;
if ( taskbar_item_from_db.name === 'explorer' ) continue;

let item = {};
if(taskbar_item_from_db.name)
item = await get_app({name: taskbar_item_from_db.name});
else if(taskbar_item_from_db.id)
item = await get_app({id: taskbar_item_from_db.id});
else if(taskbar_item_from_db.uid)
item = await get_app({uid: taskbar_item_from_db.uid});

// if item not found, skip it
if(!item) continue;

// delete sensitive attributes
delete item.id;
delete item.owner_user_id;
delete item.timestamp;
// delete item.godmode;
delete item.approved_for_listing;
delete item.approved_for_opening_items;

if ( no_icons ) {
delete item.icon;
} else {
const svc_appIcon = services.get('app-icon');
const icon_result = await svc_appIcon.get_icon_stream({
app_icon: item.icon,
Expand All @@ -1534,10 +1539,10 @@ async function get_taskbar_items(user, { icon_size } = {}) {

item.icon = resp_data_url;
}

// add to final object
taskbar_items.push(item)
}

// add to final object
taskbar_items.push(item)
}

return taskbar_items;
Expand Down
4 changes: 3 additions & 1 deletion src/backend/src/routers/whoami.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ const WHOAMI_GET = eggspress('/whoami', {
desktop_bg_fit: req.user.desktop_bg_fit,
is_temp: (req.user.password === null && req.user.email === null),
taskbar_items: await get_taskbar_items(req.user, {
...(req.query.icon_size ? { icon_size: req.query.icon_size } : {})
...(req.query.icon_size
? { icon_size: req.query.icon_size }
: { no_icons: true }),
}),
referral_code: req.user.referral_code,
otp: !! req.user.otp_enabled,
Expand Down

0 comments on commit cb2653b

Please sign in to comment.