Skip to content
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

Feat/cold data #2643

Merged
merged 2 commits into from
Nov 28, 2024
Merged
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
5 changes: 3 additions & 2 deletions packages/itmat-apis/src/trpc/dataProcedure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export class DataRouter {
fieldIds: z.optional(z.array(z.string())),
useCache: z.optional(z.boolean()),
forceUpdate: z.optional(z.boolean()),
formatted: z.optional(z.string())
fromCold: z.optional(z.boolean())
})).query(async (opts) => {
return await this.dataCore.getData(
opts.ctx.req.user,
Expand All @@ -207,7 +207,8 @@ export class DataRouter {
opts.input.versionId,
opts.input.aggregation,
opts.input.useCache,
opts.input.forceUpdate
opts.input.forceUpdate,
opts.input.fromCold
);
}),
/**
Expand Down
15 changes: 10 additions & 5 deletions packages/itmat-cores/src/coreFunc/dataCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ export class DataCore {
*
* @return Partial<IData>[] - The list of objects of Partial<IData>
*/
public async getData(requester: IUserWithoutToken | undefined, studyId: string, selectedFieldIds?: string[], dataVersion?: string | null | Array<string | null>, aggregation?: Record<string, Array<{ operationName: enumDataTransformationOperation, params: Record<string, unknown> }>>, useCache?: boolean, forceUpdate?: boolean) {
public async getData(requester: IUserWithoutToken | undefined, studyId: string, selectedFieldIds?: string[], dataVersion?: string | null | Array<string | null>, aggregation?: Record<string, Array<{ operationName: enumDataTransformationOperation, params: Record<string, unknown> }>>, useCache?: boolean, forceUpdate?: boolean, fromCold?: boolean) {
if (!requester) {
throw new CoreError(
enumCoreErrors.NOT_LOGGED_IN,
Expand Down Expand Up @@ -811,7 +811,7 @@ export class DataCore {
return await getJsonFileContents(this.objStore, 'cache', hashedInfo[0].uri);
} else {
// raw data by the permission
const data = await this.getDataByRoles(requester, roles, studyId, availableDataVersions, fieldIds);
const data = await this.getDataByRoles(requester, roles, studyId, availableDataVersions, fieldIds, fromCold);
// data transformation if aggregation is provided
const transformed = aggregation ? this.dataTransformationCore.transformationAggregate(data as unknown as IDataTransformationClipArray, aggregation) : data;
// write to minio and cache collection
Expand Down Expand Up @@ -843,7 +843,7 @@ export class DataCore {
}
} else {
// raw data by the permission
const data = await this.getDataByRoles(requester, roles, studyId, availableDataVersions, fieldIds);
const data = await this.getDataByRoles(requester, roles, studyId, availableDataVersions, fieldIds, fromCold);
// data transformation if aggregation is provided
const transformed = aggregation ? this.dataTransformationCore.transformationAggregate(data as unknown as IDataTransformationClipArray, aggregation) : data;
return transformed;
Expand Down Expand Up @@ -1275,12 +1275,14 @@ export class DataCore {
}


public async getDataByRoles(requester: IUserWithoutToken, roles: IRole[], studyId: string, dataVersions: Array<string | null>, fieldIds?: string[]) {
public async getDataByRoles(requester: IUserWithoutToken, roles: IRole[], studyId: string, dataVersions: Array<string | null>, fieldIds?: string[], fromCold?: boolean) {
const matchFilter: Filter<IData> = {
studyId: studyId,
dataVersion: { $in: dataVersions }
};

const dbCollection = fromCold ? this.db.collections.colddata_collection : this.db.collections.data_collection;

const roleArr: Filter<IData>[] = [];
for (const role of roles) {
const permissionArr: Filter<IData>[] = [];
Expand Down Expand Up @@ -1316,12 +1318,15 @@ export class DataCore {
const queryField = async (fieldId: string) => {
if (availableFieldIds.includes(fieldId) || availableFieldIds.some(el => new RegExp(el).test(fieldId))) {
const propertyFilter: Record<string, string> = {};
if (!availableFields[fieldId]) {
return [];
}
if (availableFields[fieldId].properties) {
for (const property of availableFields[fieldId].properties) {
propertyFilter[`${property.name}`] = `$properties.${property.name}`;
}
}
const data = await this.db.collections.data_collection.aggregate<IData>([{
const data = await dbCollection.aggregate<IData>([{
$match: {
...matchFilter,
fieldId: fieldId,
Expand Down
2 changes: 1 addition & 1 deletion packages/itmat-interface/src/server/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class Router {
this.app.use(rateLimit({
windowMs: 1 * 60 * 1000,
max: async function (req) {
const minimumQPS = 1000;
const minimumQPS = 5000;
let qps = minimumQPS;
if (req.user) {
const userConfig = await db.collections.configs_collection.findOne({ type: enumConfigType.USERCONFIG, key: req.user.id });
Expand Down
1 change: 1 addition & 0 deletions packages/itmat-types/src/types/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export enum enumFileTypes {
DOCX = 'DOCX',
XLSX = 'XLSX',
XLS = 'XLS',
MAT = 'MAT',
// images
JPG = 'JPG',
JPEG = 'JPEG',
Expand Down
2 changes: 1 addition & 1 deletion packages/itmat-ui-react/src/Fence.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const Fence: FunctionComponent = () => {

const whoAmI = trpc.user.whoAmI.useQuery();
const recoverSession = trpc.user.recoverSessionExpireTime.useQuery(undefined, {
refetchInterval: 60 * 60 * 1000
refetchInterval: 30 * 60 * 1000
});

const [component, setComponent] = useState<JSX.Element | null>(null);
Expand Down