Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

fix: After the application name change - the application name on the demo page has not been updated

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Aug 4, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Aug 4, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

del_application_access_token(access_token)
return self.one(with_valid=False)

@staticmethod
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are a few areas to consider for improvement:

  1. Code Duplication:

    from common.cache_data.application_access_token_cache import del_application_access_token

    This line can be moved out of the function, so it's only called once.

  2. Redundant Code: The following lines:

    access_token = hashlib.md5(str(uuid.uuid7()).encode()).hexdigest()[8:24]
    application_access_token = QuerySet(ApplicationAccessToken).filter(application_id=application.id).first()
    if application_access_token is None:
        application_access_token = ApplicationAccessToken(application_id=application.id,
                                                          access_token=access_token, is_active=True)
        application_access_token.save()
    else:
        access_token = application_access_token.access_token

    could be combined into one more concise statement using get_or_create method:

    application_access_token, _ = ApplicationAccessToken.objects.get_or_create(
        application_id=application.id,
        defaults={'access_token': hashlib.md5(str(uuid.uuid7()).encode()).hexdigest()[8:24], 'is_active': True}
    )
  3. Avoid Unused Imports:
    Ensure that imports you're not actually using should be removed from your file.

  4. Documentation Comments:
    Add comments where necessary to describe complex blocks of code or logic flows, which will make maintenance easier down the road.

Following these recommendations leads to cleaner and potentially more efficient code like this:

from langchain_mcp_adapters.client import MultiServerMCPClient
from rest_framework import serializers, status
from rest_framework.utils.formatting import lazy_format

from application.flow.common import Workflow
from application.models.application import (
    Application,
    ApplicationTypeChoices,
    ApplicationKnowledgeMapping,
    ApplicationFolder,
    ApplicationVersion
)
from application.models.application_access_token import ApplicationAccessToken
from common import result
from common.database_model_manage import DatabaseModelManage
from common.db.search import native_search, native_page_search
from common.exception.app_exception import AppApiException

class YourClass:
    # Function implementation here...
    
    def publish(self, instance, with_valid=True):
        # Function body remains largely the same...

    @staticmethod
    def get_or_update_app_access_token(application):
        return ApplicationAccessToken.objects.get_or_create(
            application_id=application.id,
            defaults={
                'access_token': hashlib.md5(str(uuid.uuid7()).encode()).hexdigest()[8:24],
                'is_active': True
            }
        )

# Call within your method as needed:
token, created = get_or_update_app_access_token(instance.application)

By applying some of these suggestions, your codebase becomes leaner while maintaining readability and functionality integrity.

@shaohuzhang1 shaohuzhang1 merged commit fe94ca5 into v2 Aug 4, 2025
3 of 5 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@v2@fix_application_name branch August 4, 2025 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants