Skip to content

Commit

Permalink
fix(server, kanban): increased executable performance
Browse files Browse the repository at this point in the history
  • Loading branch information
thesophiaxu committed Jan 14, 2022
1 parent b61100e commit b4f0731
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ const List = React.useMemo(() => {
<b>{column._value.name['_value.%']}</b>
</Typography>
<DynamicObjectListView
items={
(listValue?.['_value['] || []).sort(byElementIndex) ||
[]
}
items={(listValue?.['_value['] || []).sort(byElementIndex) || []}
context={column}
listUid={listValue?.uid}
callbacks={{ ...callbacks }}
Expand All @@ -44,8 +41,7 @@ const List = React.useMemo(() => {
onClick={() => {
unigraph.getState('global/omnibarSummoner').setValue({
show: true,
tooltip:
'Press Enter to add current item to current Kanban column',
tooltip: 'Press Enter to add current item to current Kanban column',
callback: (uid) => {
unigraph.runExecutable(
'$/executable/add-item-to-list',
Expand All @@ -54,6 +50,9 @@ const List = React.useMemo(() => {
item: uid,
subIds: [callbacks?.subsId],
},
undefined,
undefined,
true,
);
},
defaultValue: '+',
Expand All @@ -74,9 +73,7 @@ const SetBgim = React.useMemo(() => {

return (
<div style={{ paddingTop: '2px', paddingBottom: '2px' }}>
<Typography style={{ color: 'grey' }}>
Set new background image
</Typography>
<Typography style={{ color: 'grey' }}>Set new background image</Typography>
<TextField
value={bgimText}
onChange={(e) => {
Expand All @@ -86,12 +83,7 @@ const SetBgim = React.useMemo(() => {
<Button
onClick={() => {
handleClose();
unigraph.updateObject(
data.uid,
{ _backgroundImage: bgimText },
false,
false,
);
unigraph.updateObject(data.uid, { _backgroundImage: bgimText }, false, false);
}}
>
Set
Expand Down Expand Up @@ -154,29 +146,19 @@ return (
}}
>
<div style={{ display: 'flex' }}>
<Typography
variant="h5"
gutterBottom
style={{ marginTop: '8px', width: '100%' }}
>
<Typography variant="h5" gutterBottom style={{ marginTop: '8px', width: '100%' }}>
{data.get('title').as('primitive')}
</Typography>
<MoreVert
onClick={(event) =>
onUnigraphContextMenu(
event,
data,
undefined,
callbacks,
(uid, object, handleClose, callbacks) => {
return (
<div>
<SetBgim handleClose={handleClose} />
<AddBoard handleClose={handleClose} />
</div>
);
},
)
onUnigraphContextMenu(event, data, undefined, callbacks, (uid, object, handleClose, callbacks) => {
return (
<div>
<SetBgim handleClose={handleClose} />
<AddBoard handleClose={handleClose} />
</div>
);
})
}
style={{ marginLeft: '8px' }}
/>
Expand All @@ -185,10 +167,7 @@ return (
{data
.get('children')
['_value['].sort(byElementIndex)
.filter(
(el) =>
el?._value?.type?.['unigraph.id'] === '$/schema/list',
)
.filter((el) => el?._value?.type?.['unigraph.id'] === '$/schema/list')
.map((el) => (
<List column={el._value} />
))}
Expand Down
1 change: 1 addition & 0 deletions packages/unigraph-dev-backend/src/custom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ declare type EventRunExecutable = {
id: number,
"uid": string,
params: any,
bypassCache?: boolean,
}

declare type EventAddNotification = {
Expand Down
43 changes: 25 additions & 18 deletions packages/unigraph-dev-backend/src/localUnigraphApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,25 +425,32 @@ export function getLocalUnigraphAPI(
proxyFetch: async (url, options?) => new Blob([]),
// latertodo
importObjects: async (objects) => Error('Not implemented'),
runExecutable: async (uid: string, params: any, context?: ExecContext) => {
runExecutable: async (
uid: string,
params: any,
context?: ExecContext,
fnString?: any,
bypassCache?: boolean,
) => {
let ret;
await states.lock.acquire('caches/exec', async (done: any) => {
const exec = uid.startsWith('0x')
? unpad((await client.queryUID(uid))[0])
: states.caches.executables.data[uid];
const execFn = await buildExecutable(
exec,
{ params, definition: exec, ...context },
states.localApi,
states,
);
if (typeof execFn === 'function') {
ret = execFn();
} else if (typeof execFn === 'string') {
ret = { return_function_component: execFn };
} else ret = {};
done(false, null);
});
if (!bypassCache)
await states.lock.acquire('caches/exec', async (done: any) => {
done(false, null);
});
const exec = uid.startsWith('0x')
? unpad((await client.queryUID(uid))[0])
: states.caches.executables.data[uid];
const execFn = await buildExecutable(
exec,
{ params, definition: exec, ...context },
states.localApi,
states,
);
if (typeof execFn === 'function') {
ret = execFn();
} else if (typeof execFn === 'string') {
ret = { return_function_component: execFn };
} else ret = {};
return ret;
},
addNotification: async (notification) => {
Expand Down
5 changes: 2 additions & 3 deletions packages/unigraph-dev-backend/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,7 @@ export default async function startServer(client: DgraphClient) {
if (event.usedUids) {
serverStates.leasedUids = _.difference(serverStates.leasedUids, event.usedUids)
Object.entries(serverStates.clientLeasedUids).forEach(([connId, el]: any[]) => {
serverStates.clientLeasedUids[connId] = _.difference(el, event.usedUids as any[])
console.log(connId, serverStates.clientLeasedUids[connId])
serverStates.clientLeasedUids[connId] = _.difference(el, event.usedUids as any[]);
})
};
callHooks(serverStates.hooks, "after_object_changed", {subscriptions: serverStates.subscriptions, caches: caches, subIds: event.subIds, ofUpdate: event.id})
Expand Down Expand Up @@ -639,7 +638,7 @@ export default async function startServer(client: DgraphClient) {
},

"run_executable": async function (event: EventRunExecutable, ws: IWebsocket) {
localApi.runExecutable(event.uid, event.params, {send: (it: string) => {ws.send(it)}})
localApi.runExecutable(event.uid, event.params, {send: (it: string) => {ws.send(it)}}, undefined, event.bypassCache)
.then((ret: any) => ws.send(makeResponse(event, true, {returns: ret})));
},

Expand Down
4 changes: 2 additions & 2 deletions packages/unigraph-dev-common/src/api/unigraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ export default function unigraph(url: string, browserId: string): Unigraph<WebSo
const id = getRandomInt();
sendEvent(connection, 'import_objects', { objects }, id);
}),
runExecutable: (uid, params?, context?, fnString?) =>
runExecutable: (uid, params?, context?, fnString?, bypassCache?) =>
new Promise((resolve, reject) => {
const id = getRandomInt();
callbacks[id] = (response: any) => {
Expand All @@ -619,7 +619,7 @@ export default function unigraph(url: string, browserId: string): Unigraph<WebSo
}
} else reject(response);
};
sendEvent(connection, 'run_executable', { uid, params: params || {} }, id);
sendEvent(connection, 'run_executable', { uid, params: params || {}, bypassCache }, id);
}),
getNamespaceMapUid: (name) => {
throw Error('Not implemented');
Expand Down
2 changes: 1 addition & 1 deletion packages/unigraph-dev-common/src/types/unigraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ export interface Unigraph<TT = WebSocket | false> {
* @param params The parameters defined for that executable.
* @param fnString Whether to return the executable function as a function or stirng.
*/
runExecutable<T>(uid: string, params: T, context?: any, fnString?: boolean): Promise<any>;
runExecutable<T>(uid: string, params: T, context?: any, fnString?: boolean, bypassCache?: boolean): Promise<any>;
/**
* Adds a notification to the global notification list.
*
Expand Down

0 comments on commit b4f0731

Please sign in to comment.