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

[Optimization] Use O(logn) complexity to get the Google Product Category String #19

Open
Solodye opened this issue Jun 14, 2024 · 0 comments

Comments

@Solodye
Copy link

Solodye commented Jun 14, 2024

Why here uses String value -> id format?

def convert_gpc_id_to_string(self, gpc: Union[str, int]) -> str:
"""Looks up and returns the string format of the GPC if it is a number."""
if isinstance(gpc, int) or gpc.isdigit():
gpc_string = ''
for key, value in self._gpc_string_to_id_mapping.items():
if value == int(gpc):
gpc_string = key
break
return gpc_string or ''
else:
return gpc

If I have a Google Product Categoty = 6797, Python needs to iterate 5437 values to find the String 食品・飲料 > 飲料 > バターミルク , this will be a huge performance issue.

"食品・飲料 > 飲料 > バターミルク": 6797,

So, from my opinion, we need to init an id -> String value dictionary, then use o(logn) complexity to get the String

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

No branches or pull requests

1 participant