Skip to content

Conversation

@boyce-pj
Copy link
Contributor

Commiting code from Adam Beck and Lewis Cooley

di/cache/init.q Outdated
Comment on lines 4 to 9
export:([
getperf:getperf;
sdd:add;
drop:drop;
execute:execute
])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export:([
getperf:getperf;
sdd:add;
drop:drop;
execute:execute
])
export:([getperf;add;drop;execute])

assuming sdd was a typo

di/cache/cache.q Outdated
Comment on lines 3 to 4
/ return timestamp function
cp:{.z.p};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there doesn't appear to be a way to change this for end-users, so might make more sense to just use .z.p directly instaed of having this function?

di/cache/cache.q Outdated

// Drop some ids from the cache
drop:{[ids]
ids,:();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inconsistent indentation between different functions in this file, align to style guide please

Comment on lines +34 to +36
/ Don't trap the error here - if it throws an error, we want it to be propagated out
res:value function;
$[(maxindividual*MB)>size:-22!res;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inconsistent indentation

Comment on lines +6 to +13
/ the maximum size of the cache in MB
maxsize:10;

/ the maximum size of any individual result set in MB
maxindividual:50;

/ make sure the maxindividual isn't bigger than maxsize
maxindividual:maxsize&maxindividual;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should have a function for users to change these config settings

/ make sure the maxindividual isn't bigger than maxsize
maxindividual:maxsize&maxindividual;

MB:2 xexp 20;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a comment to explain this

/ Return the result
res};

// Drop some ids from the cache
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments from here onwards use // instead of /

/ check if we need more space to store this item
[now:cp[];
if[0>requiredsize:(maxsize*MB) - size+sum exec size from cache; evict[neg requiredsize;now]];
/ Insert to the cache table
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments should start with lowercase as per style guide

Comment on lines +36 to +48
$[(maxindividual*MB)>size:-22!res;
/ check if we need more space to store this item
[now:cp[];
if[0>requiredsize:(maxsize*MB) - size+sum exec size from cache; evict[neg requiredsize;now]];
/ Insert to the cache table
.z.M.cache upsert (id;now;now;size);
/ and insert to the function and results dictionary
funcs[id]:enlist function;
results[id]:enlist res;
/ Update the performance
trackperf[id;status;now]];
/ Otherwise just log it as an addfail - the result set is too big
trackperf[id;`fail;cp[]]];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be worth refactoring this to avoid the code block inside $ https://github.com/DataIntellectTech/kdbx-modules/blob/main/style.md#conditionals-and-execution-control

e.g. something like this, reversing the condition & returning early if the result is too large

Suggested change
$[(maxindividual*MB)>size:-22!res;
/ check if we need more space to store this item
[now:cp[];
if[0>requiredsize:(maxsize*MB) - size+sum exec size from cache; evict[neg requiredsize;now]];
/ Insert to the cache table
.z.M.cache upsert (id;now;now;size);
/ and insert to the function and results dictionary
funcs[id]:enlist function;
results[id]:enlist res;
/ Update the performance
trackperf[id;status;now]];
/ Otherwise just log it as an addfail - the result set is too big
trackperf[id;`fail;cp[]]];
if[(maxindividual*MB)<=size:-22!res;
/ log it as an addfail - the result set is too big
trackperf[id;`fail;cp[]];
:res;
];
/ check if we need more space to store this item
now:cp[];
if[0>requiredsize:(maxsize*MB) - size+sum exec size from cache;
evict[neg requiredsize;now];
];
/ Insert to the cache table
.z.M.cache upsert (id;now;now;size);
/ and insert to the function and results dictionary
funcs[id]:enlist function;
results[id]:enlist res;
/ Update the performance
trackperf[id;status;now]];

/ Load core functionality into root module namespace
\l ::cache.q

export:([getperf;add;drop;execute])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think add or drop should be exposed to end users, I don't think we'd expect them to be using those functions directly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants