This repository was archived by the owner on Apr 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.R
More file actions
38 lines (34 loc) · 1.34 KB
/
functions.R
File metadata and controls
38 lines (34 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
arrayList <- function() {
arrayList = iquery(db, "project(filter(list(), temporary=FALSE), name)", return=TRUE)$name
notR_arrays = !(grepl("R_array+", arrayList, perl=TRUE))
arrayList[notR_arrays]
}
nmspList <- function() {
iquery(db, "list('namespaces')", return=TRUE)$name
}
get_array_stats = function(array, useCache = TRUE) {
if (useCache){
query = sprintf("project(versions(%s), version_id)", array)
dims = "VersionNo"
attribs = "version_id"
TYPES = "int64"
NULLABILTY = FALSE
# t1 = proc.time();
key = sprintf("scidb:%s", array)
latest_version_in_db = max(query_to_df(query, dims, attribs, TYPES, NULLABILTY)$version_id);
latest_cache = redisGet(key)
latest_version_in_cache = latest_cache[[1]]
if (latest_version_in_db == latest_version_in_cache) {
latest_array_stats = latest_cache[[2]]
} else {
latest_array_stats = iquery(db, sprintf("project(summarize(%s, by_instance:true), count, bytes)", array), return = TRUE)
redisSet(sprintf(key, list(latest_version_in_db, latest_array_stats)))
}
# print(proc.time()-t1)
} else {
# t1 = proc.time();
latest_array_stats = iquery(db, sprintf("project(summarize(%s, by_instance:true), count, bytes)", array), return = TRUE);
# print(proc.time()-t1)
}
return(latest_array_stats[, c("inst", "count", "bytes")])
}