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

Optimize total_installs for /plugin/index #1040

Merged
merged 6 commits into from
May 10, 2023
Merged

Conversation

manasaV3
Copy link
Collaborator

@manasaV3 manasaV3 commented May 10, 2023

Description

Relates to: #1042

Changes introduced:

  • Adds a new index to install-activity table on the plugin_name, and is_total field

  • Adds the is_total attribute only to the records of type=TOTAL in data workflow

  • In backend, updates the data fetch from batch get to scan of the table.

Notes:

  • On deploy of this changes, the activity workflow needs to be executed from start of time.

richaagarwal
richaagarwal previously approved these changes May 10, 2023
Copy link
Collaborator

@richaagarwal richaagarwal left a comment

Choose a reason for hiding this comment

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

Approving for now to help get this change in, but I would recommend not passing around an additional variable is_total for instantiating InstallActivity, since it's redundant with an existing variable activity_type that we can utilize. The mix of positional and keyword arguments here is a little confusing as well, ideally we would only mix them if one of the arguments was optional.

@manasaV3
Copy link
Collaborator Author

I would recommend not passing around an additional variable is_total for instantiating InstallActivity, since it's redundant with an existing variable activity_type that we can utilize.

With how the pynamo Model's are initialized, refactoring that to be evaluated in the __init__ method from the granularity attribute will add more complexity to the code. The code would look something like:

  def __init__(
            self, hash_key=None, range_key=None,  _user_instantiated: bool = True, **attributes: Any,
    ) -> None:
        if attributes.get('granularity') == InstallActivityType.TOTAL.name:
            attributes['is_total'] = 'true'

        super(InstallActivity, self).__init__(
            hash_key=hash_key,
            range_key=range_key,
            _user_instantiated=_user_instantiated,
            **attributes
        )

So, I am more in favor of computing it outside and passing it on as an attribute. As an added advantage, we compute just once to determine the value of is_total.

The mix of positional and keyword arguments here is a little confusing as well, ideally we would only mix them if one of the arguments was optional.

I agree, we should avoid mixing keyword and positional arguments and lean towards keyword arguments in such cases. Updating the code to reflect that.

@manasaV3 manasaV3 requested review from codemonkey800 and klai95 May 10, 2023 19:44
@manasaV3 manasaV3 merged commit 1ae21a9 into main May 10, 2023
@manasaV3 manasaV3 deleted the get-total-optimization branch May 10, 2023 23:15
@richaagarwal richaagarwal added the improvement Release Label: Used for categorizing improvements in automated CI release notes label May 11, 2023
for item in _InstallActivityModel.total_installs.scan():
if item.plugin_name in plugins:
results[item.plugin_name] = item.install_count

duration = (time.perf_counter() - start) * 1000
logging.info(f'BatchGet for total_installs_by_plugins time_taken={duration}ms')
Copy link
Collaborator

Choose a reason for hiding this comment

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

@manasaV3 Sorry I missed this before, but let's make sure to update the logging statements too that still reference BatchGet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Release Label: Used for categorizing improvements in automated CI release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants