Commit e03b5a08fabd9ab583105c9e8e21075a57df8eba
1 parent
a15f8ef2
add to_fs_folder from DB_id
* produce path from db_id to optimize fs access and never have more than 100 folders
Showing
1 changed file
with
23 additions
and
2 deletions
Show diff stats
database/db_types.anubis
| @@ -77,8 +77,29 @@ public define DB_id | @@ -77,8 +77,29 @@ public define DB_id | ||
| 77 | else | 77 | else |
| 78 | db_id(value) | 78 | db_id(value) |
| 79 | . | 79 | . |
| 80 | - | ||
| 81 | - | 80 | + |
| 81 | +/** | ||
| 82 | + * produce path from db_id to optimize fs access and never have more than 100 folders | ||
| 83 | + */ | ||
| 84 | +public define String | ||
| 85 | + to_fs_folder | ||
| 86 | + ( | ||
| 87 | + DB_id idx | ||
| 88 | + )= | ||
| 89 | + if idx is | ||
| 90 | + { | ||
| 91 | + none then "none/", | ||
| 92 | + db_id(_idx) then | ||
| 93 | + with idx_str = abs_to_decimal(_idx), | ||
| 94 | + //if the idx value is less than 10, we add 0 as prefix of that idx. i.e. if the idx is 3 the final_idx_str will be 03 which will be cut as 0/3/. | ||
| 95 | + //the idx < 10 will be located in the 0 folder. | ||
| 96 | + with final_idx_str= if _idx < 10 then "0"+idx_str else idx_str, | ||
| 97 | + with result_path = join("/", reverse(map_select((Bool first, Word8 char) |-> if first then (false, failure) else (false, success(implode([char]))), true, reverse(explode(final_idx_str)))) + [idx_str])+"/", | ||
| 98 | + println("to_fs_folder result_path "+result_path); | ||
| 99 | + result_path | ||
| 100 | + } | ||
| 101 | +. | ||
| 102 | + | ||
| 82 | public define String | 103 | public define String |
| 83 | to_String | 104 | to_String |
| 84 | ( | 105 | ( |