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

fix of subscribe to search - an open issue in the web #459 #190

Closed
wants to merge 1 commit into from

Conversation

KlaraK94
Copy link
Contributor

With the last changes, we made sure no duplications were added to search (after discussion with Mircea). But I do think duplications is necessary. The users can both add the same search subscription, but the issue is when removing the subscription again. Because there should then be two objects, where each user can delete "their own". But not having duplications results in only one object in the database, and neither/only one can remove the search.

This is a fix of an open issue in the web, zeeguu/web#459.

Copy link

Module view diffs:
diff

Copy link
Collaborator

@tfnribeiro tfnribeiro left a comment

Choose a reason for hiding this comment

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

With the last changes, we made sure no duplications were added to search (after discussion with Mircea). But I do think duplications is necessary. The users can both add the same search subscription, but the issue is when removing the subscription again. Because there should then be two objects, where each user can delete "their own". But not having duplications results in only one object in the database, and neither/only one can remove the search.

This is a fix of an open issue in the web, zeeguu/web#459.

Thank you for investigating this Klara. Having duplication in a database is quite a bad idea, and after having a look myself you can see that we have a "mapping" table already, this is where we store the information of which users are interested in what searches (search_subscription). So the issue currently is the following:

    """
    A user can unsubscribe from the search with a given ID
    :return: OK / ERROR
    """

    search_id = int(request.form.get("search_id", ""))
    user = User.find_by_id(flask.g.user_id)
    try:
        to_delete = SearchFilter.with_search_id(search_id, user)
        db_session.delete(to_delete)
        to_delete = Search.find_by_id(search_id)
        db_session.delete(to_delete)
        db_session.commit()

    except Exception as e:
        log(str(e))
        from sentry_sdk import capture_exception

        capture_exception(e)
        return "OOPS. SEARCH AIN'T THERE IT SEEMS (" + str(e) + ")"

    return "OK"

If you look at the method above, we attempt to delete the Search once we delete the Search as soon as we delete the subscription. However, without duplication this will fail, because there can be other users subscribed to the same topic ('OL') in this case.

In order to delete the search, we need to ensure there are no users with that keyword subscribed to. I have made a change where this is done and I believe that's a better way to fix it.

Take a look at #191 which fixes this issue - tested with 2 users in my local environment.

@KlaraK94
Copy link
Contributor Author

It makes sense to not have duplications in the code. Thank you for the fix!

@mircealungu
Copy link
Member

closing this as it has been solved by @tfnribeiro in #191

@mircealungu mircealungu closed this Sep 5, 2024
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