Skip to content

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

@Solodye

Description

@Solodye

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions