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

add JSONFileChildSeeder class #4

Merged
merged 13 commits into from
Sep 2, 2024
Merged

Conversation

liviomendonca
Copy link
Contributor

We propose an extension of JSONFileModelSeeder which can handle child models. It has been implemented with a caching system to speed up the seeding process.

Also correct some minor typos.

Copy link
Owner

@suliman-99 suliman-99 Aug 28, 2024

Choose a reason for hiding this comment

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

First of all i should thank both of you for your contributions, i am so happy to see your commits
It is really really nice work and i like it

But I think there is redundancy in the code in this section
I find out that these two sections do the same thing and we can delete one of them
both of them get the needed object of a specific model with specific query data (dict) then store it in the hashmap and get it from it if it is requested again instead of getting it again from the database

first one between line 467 and line 477

                        if not related_keys_dict[k] in hashmap:
                            hashmap[related_keys_dict[k]] = dict()

                        tuple_v = _convert_to_tuple(v)

                        if tuple_v in hashmap[related_keys_dict[k]]:
                            entry[k] = hashmap[related_keys_dict[k]][tuple_v]

                        else:
                            entry[k] = _replace_item(v, related_keys_dict[k])
                            hashmap[related_keys_dict[k]][tuple_v] = entry[k]

second part between line 482 and line 491:

            obj_pk = _convert_to_tuple(entry)

            if not model in hashmap:
                hashmap[model] = dict()

            if obj_pk in hashmap[model]:
                return hashmap[model][obj_pk]

            hashmap[model][obj_pk] = model.objects.get(**entry)
            return hashmap[model][obj_pk]

maybe i misunderstand the code
correct me if i am wrong
and thank you in advance

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review!

You're absolutely correct! We changed our code to remove the redundancy ;)

@suliman-99 suliman-99 merged commit 776e8a3 into suliman-99:main Sep 2, 2024
1 check passed
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.

3 participants