2020-09-03 13:05:22 -07:00
|
|
|
import { any } from "underscore";
|
|
|
|
import { CollectionCreationDefaults } from "../Contracts/ViewModels";
|
2020-07-20 12:59:40 -05:00
|
|
|
import Explorer from "../Explorer/Explorer";
|
2020-05-25 21:30:55 -05:00
|
|
|
|
2020-09-03 13:05:22 -07:00
|
|
|
export const getMaxThroughput = (defaults: CollectionCreationDefaults, container: Explorer): number => {
|
|
|
|
const throughput = defaults.throughput.unlimited;
|
|
|
|
if (typeof throughput === "number") {
|
|
|
|
return throughput;
|
|
|
|
} else {
|
|
|
|
return _exceedsThreshold(throughput.collectionThreshold, container)
|
|
|
|
? throughput.greatThanThreshold
|
|
|
|
: throughput.lessThanOrEqualToThreshold;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const _exceedsThreshold = (unlimitedThreshold: number, container: Explorer): boolean => {
|
|
|
|
const databases = (container && container.databases && container.databases()) || [];
|
|
|
|
return any(
|
|
|
|
databases,
|
|
|
|
database =>
|
|
|
|
database && database.collections && database.collections() && database.collections().length > unlimitedThreshold
|
|
|
|
);
|
|
|
|
};
|