surrealdb / surrealist

Surrealist is the ultimate way to visually manage your SurrealDB database
https://surrealist.app/
MIT License
1.1k stars 84 forks source link

Surrealist UI freezes with large query body #71

Closed Andrewknackstedt closed 1 year ago

Andrewknackstedt commented 1 year ago

Describe the bug When working on a large query body, surrealist stutters and freezes, becoming difficult to use.

To Reproduce Steps to reproduce the behavior:

  1. Connect to any instance
  2. Click on 'Query'
  3. Enter attached text (below)
  4. Observe "Send Query" time out and general UI stuttering

Expected behavior Expected large body of text to be editable and no UI stuttering

Environment (you can view the current version under Settings):

Sample Query:

CREATE pipeline:ulid() CONTENT {
    label: 'test-pipeline',
    description: 'This is a test pipeline.',
    labelTemplate: '(arg) => \'foob\'',

    stages: [
        {
            label: "build",
            environment: [
                { key: "level2key", value: "level2value" },
                { key: "level2key2", value: "level2value2" }
            ],
            jobs: [
                {
                    label: "npm build",
                    runType: "1",
                    taskGroups: [
                        {
                            label: "group1",
                            environment: [
                                { key: "level4key", value: "level4value" },
                                { key: "level4key2", value: "level4value2" }
                            ]
                            tasks: [
                                {
                                    label: "test cmd",
                                    command: "echo",
                                    arguments: ["foo", "bar"],
                                    environment: [
                                        { key: "level5key", value: "level5value" },
                                        { key: "level5key2", value: "level5value2" }
                                    ]
                                }
                            ]
                        }
                    ],
                    artifacts: [
                        {
                            label: "dist",
                            source: "/source/dir",
                            destination: "/remotefs/target"
                        }
                    ],
                    environment: [
                        { key: "level3key", value: "level3value" },
                        { key: "level3key2", value: "level3value2" }
                    ]
                }
            ]
        },
        {
            label: "deploy dev"
            environment: [
                { key: "level2akey", value: "level2avalue" },
                { key: "level2akey2", value: "level2avalue2" }
            ],
            jobs: [
                {
                    label: "Deploy slot 1",
                    runType: "1",
                    taskGroups: [

                    ],
                    environment: [
                        { key: "level3akey", value: "level3avalue" },
                        { key: "level3akey2", value: "level3avalue2" }
                    ]
                },
                {
                    label: "Deploy slot 2",
                    runType: "1",
                    taskGroups: [

                    ],
                    environment: [
                        { key: "level3ckey", value: "level3cvalue" },
                        { key: "level3ckey2", value: "level3cvalue2" }
                    ]
                }
            ]
        }
    ],
    environment: [
        { key: "level1key", value: "level1value" },
        { key: "level1key2", value: "level1value2" }
    ],
    sources: [
        {
            label: "git repo",
            targetPath: "/root/folder",
            username: "knackstedt",
            url: "https://github.com/knackstedt/dot-ops"
        },
        {
            label: "lib repo",
            targetPath: "/root/lib",
            username: "knackstedt",
            url: "https://github.com/knackstedt/ngx-ctx-menu"
        }
    ]
};
Andrewknackstedt commented 1 year ago

This is the schema for reference: https://github.com/knackstedt/dot-ops/tree/main/database/02b-tables

ItsMateo commented 1 year ago

Hey there!

I was able to confirm this issue and have passed it along to the appropriate members of our team. Some of our members are currently out of town and will not be back for several days. Therefore, it might take a few extra days to resolve this issue.

Thanks for your report!

Andrewknackstedt commented 1 year ago

Thanks @ItsMateo! I'm in no rush, so don't worry about it ;). I'm just making sure you're aware of issues that users experience, because you only know if someone tells you or you yourself notice an issue

macjuul commented 1 year ago

This is a known SurrealDB issue which also affects query parsing. I would recommend going in settings and disabling "Query error checking" as that will prevent the issue from happening.

Hope that helps!

Andrewknackstedt commented 1 year ago

Please reopen -- I don't think that's the right evaluation of this issue. This is a UI stuttering issue, where Surrealist is stuttering by itself without a pending outgoing transaction. It stutters even if I'm not connected to any instances.

Therefore, that 500kb issue, while very real, is not the only problem here

macjuul commented 1 year ago

There's nothing I can do about it. Under the hood Surrealist will pass the query to SurrealDB for parsing and validation. This is supposed to return a result, however in the case of passing deeply nested objects the function will hang indefinitely, blocking the entire application and UI. There's no proper way to know whether a query will cause a crash or not.

Disabling error checker simply prevents Surrealist from passing the query to SurrealDB, circumventing this issue

Andrewknackstedt commented 1 year ago

Why does that make Surrealist freeze when it's not connected to any SurrealDB instance? Shouldn't the UI simply have an async outgoing promise pending the response?

macjuul commented 1 year ago

Remote database instances don't expose APIs to perform certain tasks. Surrealist uses an embedded version of SurrealDB internally for multiple features related to schemas and parsing (which is why some features are only available in the desktop version), hence it invokes SurrealDB from Rust which is where the application crashes beyond my control.

Andrewknackstedt commented 1 year ago

Gotcha, Thank you for explaining that to me. It may be possible to wrap that internally executed rust logic in an asynchronous parser that runs on a separate thread. I might look at that if I have the time later we'll see

macjuul commented 1 year ago

Cool, you can find the offending code in validate_query in schema.rs