Skip to content

Commit

Permalink
faster mass get or create, with an added transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
tschellenbach committed Apr 3, 2012
1 parent 1a4d7ef commit cde41a3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion django_facebook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


__license__ = 'BSD'
__version__ = '3.5.91'
__version__ = '3.5.92'
__maintainer__ = 'Thierry Schellenbach'
__email__ = '[email protected]'
__status__ = 'Production'
Expand Down
2 changes: 1 addition & 1 deletion django_facebook/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def get_facebook_graph(request=None, access_token=None, redirect_uri=None):
from django.core.cache import cache
parsed_data = None
expires = None

if hasattr(request, 'facebook'):
graph = request.facebook
_add_current_user_id(graph, request.user)
Expand Down
6 changes: 4 additions & 2 deletions django_facebook/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.http import QueryDict, HttpResponse, HttpResponseRedirect
from django.conf import settings
from django.db import models
from django.db import models, transaction
import logging
import re
from django.utils.encoding import iri_to_uri
Expand Down Expand Up @@ -146,6 +146,7 @@ def get_profile_class():
return models.get_model(app_label, model)


@transaction.commit_on_succes
def mass_get_or_create(model_class, base_queryset, id_field, default_dict,
global_defaults):
'''
Expand All @@ -160,8 +161,9 @@ def mass_get_or_create(model_class, base_queryset, id_field, default_dict,
>>> global_defaults = dict(user=request.user, list_id=1) #global defaults
'''
current_instances = list(base_queryset)
current_ids = [unicode(getattr(c, id_field)) for c in current_instances]
current_ids = set([unicode(getattr(c, id_field)) for c in current_instances])
given_ids = map(unicode, default_dict.keys())
#both ends of the comparison are in unicode ensuring the not in works
new_ids = [g for g in given_ids if g not in current_ids]
inserted_model_instances = []
for new_id in new_ids:
Expand Down
1 change: 1 addition & 0 deletions open_facebook/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ def is_authenticated(self):
me = self.me()
except facebook_exceptions.OpenFacebookException:
me = None

authenticated = bool(me)
return authenticated

Expand Down

0 comments on commit cde41a3

Please sign in to comment.