mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
0beb2898cb
Summary: Allow exceeding the daily API usage limit for a doc based on additional allocations for the current hour and minute. See the doc comment on getDocApiUsageKeysToIncr for details. This means that up to 5 redis keys may be relevant at a time for a single document. Test Plan: Updated and expanded 'Daily API Limit' tests. Reviewers: dsagal Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D3368
24 lines
836 B
TypeScript
24 lines
836 B
TypeScript
import {HomeDBManager} from 'app/gen-server/lib/HomeDBManager';
|
|
|
|
export async function getDatabase(typeormDb?: string): Promise<HomeDBManager> {
|
|
const origTypeormDB = process.env.TYPEORM_DATABASE;
|
|
if (typeormDb) {
|
|
process.env.TYPEORM_DATABASE = typeormDb;
|
|
}
|
|
const db = new HomeDBManager();
|
|
await db.connect();
|
|
await db.initializeSpecialIds();
|
|
if (origTypeormDB) {
|
|
process.env.TYPEORM_DATABASE = origTypeormDB;
|
|
}
|
|
// If this is Sqlite, we are making a separate connection to the database,
|
|
// so could get busy errors. We bump up our timeout. The rest of Grist could
|
|
// get busy errors if we do slow writes though.
|
|
const connection = db.connection;
|
|
const sqlite = connection.driver.options.type === 'sqlite';
|
|
if (sqlite) {
|
|
await db.connection.query('PRAGMA busy_timeout = 3000');
|
|
}
|
|
return db;
|
|
}
|