Skip to content

Prevent divide-by-zero errors in cache_score function #7026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
> You will need to update your FlowKit deployment to include an additional flowmachine container which sets the command to `"cache-cleanup"`.

### Fixed
- FlowDB `cache_score` function no longer throws a divide-by-zero error for empty cache tables. [#7027](https://github.com/Flowminder/FlowKit/issues/7027)

### Removed

Expand Down
4 changes: 2 additions & 2 deletions flowdb/bin/build/0030_utilities.sql
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ $$
cache_score_multiplier+POWER(1 + ln(2) / cache_half_life(), nextval('cache.cache_touches') - 2)
END
WHERE query_id=cached_query_id
RETURNING cache_score(cache_score_multiplier, compute_time, greatest(table_size(tablename, schema), 0.00001)) INTO score;
RETURNING cache_score(cache_score_multiplier, compute_time, table_size(tablename, schema)) INTO score;
IF NOT FOUND THEN RAISE EXCEPTION 'Cache record % not found', cached_query_id;
END IF;
RETURN score;
Expand All @@ -267,7 +267,7 @@ CREATE OR REPLACE FUNCTION cache_score(IN cache_score_multiplier numeric, IN com
RETURNS float AS
$$
BEGIN
RETURN cache_score_multiplier*((compute_time/1000)/tablesize);
RETURN cache_score_multiplier*((compute_time/1000)/greatest(tablesize, 0.00001));
END
$$ LANGUAGE plpgsql
SECURITY DEFINER
Expand Down