这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@timothycarambat
Copy link
Member

Add Posthog track for sub-users while preserving privacy and compliance.

@timothycarambat timothycarambat changed the title track subuser anon Posthog telemetry updates Nov 11, 2023
@timothycarambat timothycarambat merged commit 2b17bf2 into master Nov 11, 2023
@timothycarambat timothycarambat deleted the user-telem-ids branch November 11, 2023 00:02
@review-agent-prime
Copy link

server/models/telemetry.js

Instead of using a ternary operator to determine the distinctId, you can use a more readable and performant approach by using the logical OR operator. This will return the first truthy value it encounters, or the last value if none are truthy.
Create Issue

    const distinctId = subUserId || systemId;

server/endpoints/chat.js

Instead of logging the error and sending a generic error message to the client, it would be better to send the actual error message only if it does not expose any sensitive information. This would help in debugging issues faster and also provide the client with more context about what went wrong.
Create Issue

    response.status(500).json({
      id: uuidv4(),
      type: "abort",
      textResponse: null,
      sources: [],
      close: true,
      error: process.env.NODE_ENV === 'production' ? 'An error occurred' : e.message,
    });

server/endpoints/workspaces.js

Similar to the previous suggestion, it would be better to send the actual error message only if it does not expose any sensitive information. This would help in debugging issues faster and also provide the client with more context about what went wrong.
Create Issue

    response.status(500).json({
      error: process.env.NODE_ENV === 'production' ? 'An error occurred' : e.message,
    });

server/endpoints/system.js

Instead of requiring the 'bcrypt' module inside the '/request-token' endpoint, it would be more efficient to require it at the top of the file. This way, the module is loaded into memory once and can be reused across different parts of your application, improving performance.
Create Issue

    const bcrypt = require("bcrypt");

Instead of requiring the 'child_process' module inside the '/migrate' endpoint, it would be more efficient to require it at the top of the file. This way, the module is loaded into memory once and can be reused across different parts of your application, improving performance.
Create Issue

    const { execSync } = require("child_process");

It's a good practice to avoid logging sensitive information such as passwords. In the '/request-token' endpoint, if there's an error, the password is being logged. This could potentially expose sensitive user information in the logs. Consider removing the password from the logging statement.
Create Issue

    console.log(e.message);

Consider using a middleware for error handling instead of repeating the same error handling code in each endpoint. This would make your code DRY (Don't Repeat Yourself) and easier to maintain.
Create Issue

    app.use((err, req, res, next) => {
      console.error(err.message);
      res.status(500).end();
    });

const { client, distinctId } = await this.connect();
const { client, distinctId: systemId } = await this.connect();
if (!client) return;
const distinctId = !!subUserId ? `${systemId}::${subUserId}` : systemId;

Choose a reason for hiding this comment

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

Refactoring the code to use logical OR operator instead of ternary operator for determining the distinctId. This approach is more readable and performant as it returns the first truthy value it encounters, or the last value if none are truthy.

Suggested change
const distinctId = !!subUserId ? `${systemId}::${subUserId}` : systemId;
const distinctId = subUserId ? `${systemId}::${subUserId}` : systemId;

cabwds pushed a commit to cabwds/anything-llm that referenced this pull request Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants