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

Reduced number of requests from client to server #7446

Merged
merged 19 commits into from
Feb 8, 2024
Merged
Prev Previous commit
Next Next commit
Applied comments
  • Loading branch information
bsekachev committed Feb 8, 2024
commit c1da1093aeae4be9ae707821403f742b9e0d9d9e
2 changes: 1 addition & 1 deletion cvat-core/src/logger-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ Object.defineProperties(LoggerStorage.prototype.save, {
}
} catch (error: unknown) {
// if failed, put collection back
// potentially new events may be generated duting saving
// potentially new events may be generated during saving
// that is why we add this.collection
this.collection = [...collectionToSend, ...this.collection];
} finally {
Expand Down
10 changes: 5 additions & 5 deletions cvat-ui/src/components/task-page/user-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ const initialUsersStorage: {
promise: Promise<User[]>,
timestamp: number,
}>,
get(userID?: number, organizationSLUG?: string): Promise<User[]>;
get(userID?: number, organizationSlug?: string): Promise<User[]>;
} = {
storage: {},
get(userID?: number, organizationSLUG?: string): Promise<User[]> {
get(userID?: number, organizationSlug?: string): Promise<User[]> {
if (typeof userID === 'undefined') {
return Promise.resolve([]);
}

const key = `${userID}_${organizationSLUG || ''}`;
const key = `${userID}_${organizationSlug || ''}`;
const RELOAD_INITIAL_USERS_AFTER_MS = 300000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isnt this number too large?

Copy link
Member Author

@bsekachev bsekachev Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see any problems with 5 minutes. If user can't see somebody's name, typical behavior is to start entering this name. This memoization will by bypassed.

if (key in this.storage && (Date.now() - this.storage[key].timestamp) < RELOAD_INITIAL_USERS_AFTER_MS) {
return this.storage[key].promise;
Expand Down Expand Up @@ -85,8 +85,8 @@ export default function UserSelector(props: Props): JSX.Element {
useEffect(() => {
const state = getCVATStore().getState();
const userID = state.auth.user?.id;
const organizationSLUG = state.organizations.current?.slug;
initialUsersStorage.get(userID, organizationSLUG).then((result: User[]) => {
const organizationSlug = state.organizations.current?.slug;
initialUsersStorage.get(userID, organizationSlug).then((result: User[]) => {
if (result) {
setInitialUsers(result);
}
Expand Down
2 changes: 1 addition & 1 deletion cvat-ui/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ window.addEventListener('error', (errorEvent: ErrorEvent): boolean => {
typeof colno === 'number' && error
) {
// weird react behaviour
// it also gets event only in development environment, caugth and handled in componentDidCatch
// it also gets event only in development environment, caught and handled in componentDidCatch
// discussion is here https://github.com/facebook/react/issues/10474
// and workaround is:
if (error.stack && error.stack.indexOf('invokeGuardedCallbackDev') >= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ context('Test annotations saving works correctly', () => {
let taskID = null;
let jobID = null;

function clickShortcut(clientID, shortcut) {
function useShortcut(clientID, shortcut) {
cy.get('body').click();
cy.get(`#cvat-objects-sidebar-state-item-${clientID}`).trigger('mouseover');
cy.get(`#cvat-objects-sidebar-state-item-${clientID}`).should('have.class', 'cvat-objects-sidebar-state-active-item');
Expand Down Expand Up @@ -65,7 +65,7 @@ context('Test annotations saving works correctly', () => {
});
});

describe('Check object saving works correct', () => {
describe('Check object saving works correctly', () => {
it('Create different objects, save twice. Update, delete. Export hash works as expected', () => {
// client id 1
cy.createRectangle({
Expand Down Expand Up @@ -180,7 +180,7 @@ context('Test annotations saving works correctly', () => {
cy.saveJob();

for (const clientID of [1, 2, 3, 4, 5, 6, 7, 13]) {
clickShortcut(clientID, 'q');
useShortcut(clientID, 'q');
}

cy.saveJob();
Expand All @@ -193,7 +193,7 @@ context('Test annotations saving works correctly', () => {
cy.saveJob();

for (const clientID of [1, 2, 3, 4, 5, 6, 7, 13, 19]) {
clickShortcut(clientID, '{shift}{del}');
useShortcut(clientID, '{shift}{del}');
cy.get(`#cvat-objects-sidebar-state-item-${clientID}`).should('not.exist');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ context('Task status updated after initial save.', () => {

describe(`Testing "${labelName}"`, () => {
it('State of the created task should be "new".', () => {
cy.intercept('GET', /\/api\/users.*/).as('searchUsers');
cy.openTask(taskName);
cy.get('.cvat-job-item .cvat-job-item-state').invoke('text').should('equal', 'New');
cy.wait('@searchUsers');
});

it('Create object, save annotation, state should be "in progress"', () => {
Expand Down
Loading