Skip to content

Commit

Permalink
close #2 (remove_duplicates optimization)
Browse files Browse the repository at this point in the history
  • Loading branch information
nzinov committed Mar 28, 2014
1 parent a863d20 commit 4506ec5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
19 changes: 16 additions & 3 deletions handlers/remove_duplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,26 @@ def handle_game(self, game):
game.hash = hasher.hexdigest()
game.put_async()

def get(self):
GameHistory(json_string='a').put()
GameHistory(json_string='a').put()
GameHistory(json_string='b').put()

This comment has been minimized.

Copy link
@denspb

denspb Mar 28, 2014

Member

What is this??

This comment has been minimized.

Copy link
@nzinov

nzinov Mar 28, 2014

Author Contributor

Stubs generator for debugging purposes

GameHistory(json_string='c').put()
GameHistory(json_string='c').put()
GameHistory(json_string='c').put()

@ndb.toplevel
def post(self):
stage = self.request.get('stage')
c = ndb.Cursor(urlsafe=self.request.get('cursor'))

This comment has been minimized.

Copy link
@denspb

denspb Mar 28, 2014

Member

Does it work correctly if request.get('cursor') is None?

if stage == 'hash':
GameHistory.query().map(self.handle_game)
games, curs, more = GameHistory.query().fetch_page(10, start_cursor=c)
map(self.handle_game, games)
if len(games) > 0 and more and curs:
taskqueue.add(url='/remove_duplicates',

This comment has been minimized.

Copy link
@denspb

denspb Mar 28, 2014

Member

from webapp2 import uri_for

uri_for(link name goes here)

params={'stage': 'hash', 'cursor': curs.urlsafe()},
queue_name='fast')
elif stage == 'mark':
c = ndb.Cursor(urlsafe=self.request.get('cursor'))
game, curs, more = GameHistory.query().fetch_page(1, start_cursor=c)
game = game[0]
if game is None:
Expand All @@ -35,7 +48,7 @@ def post(self):
for el in duplicates:
el.ignored = True
ndb.put_multi(duplicates)
if more:
if more and curs:
taskqueue.add(url='/remove_duplicates',
params={'stage': 'mark', 'cursor': curs.urlsafe()},
queue_name='fast')
Expand Down
5 changes: 3 additions & 2 deletions handlers/statistics/word_statistics_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ def get(self, *args, **kwargs):
entity, games, top, bottom, rand = None, None, None, None, None
if word:
entity = ndb.Key(GlobalDictionaryWord, word).get()
if entity:
games = []
for id in entity.used_games:
games.append(ndb.Key('GameLog', id).urlsafe())
for id in entity.used_legacy_games:
games.append(ndb.Key('GameHistory', id).urlsafe())

if not entity:
else:
top = memcache.get("words_top")
if not top:
top = GlobalDictionaryWord.query(projection=[GlobalDictionaryWord.E, GlobalDictionaryWord.word]).\
Expand All @@ -46,6 +46,7 @@ def get(self, *args, **kwargs):
memcache.set("used_words_count", c)
if c >= 10:
rand = q.fetch(limit=10, offset=randint(0, c-10))

self.draw_page('statistics/word_statistic', word=word, word_entity=entity, games=games,
top=top, bottom=bottom, rand=rand)

6 changes: 3 additions & 3 deletions templates/statistics/word_statistic.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{% for word in list %}
<tr>
<td>{{ loop.index }}</td>
<td><a href="statistics/word_statistics?word={{ word.word }}">{{ word.word }}</a></td>
<td><a href="word_statistics?word={{ word.word }}">{{ word.word }}</a></td>
<td>{{ word.E|round(1) }}</td>
</tr>
{% endfor %}
Expand All @@ -31,7 +31,7 @@
<div class="alert alert-danger">К сожалению, в нашем словаре нет слова "{{ word }}"</div>
{% endif %}
<h2>Выберите, статистику по какому слову вы хотите посмотреть:</h2>
<form style="margin-left: 30px" class="form-inline" method="get" action="statistics/word_statistics">
<form style="margin-left: 30px" class="form-inline" method="get" action="word_statistics">
<div class="form-group">
<input type="search" class="form-control" name="word" placeholder="Слово">
</div>
Expand All @@ -58,7 +58,7 @@ <h2>Выберите, статистику по какому слову вы х
<div class="row">
<div class="col-md-6"><p class="lead">Показана статистика по слову "{{ word_entity.word }}"</p></div>
<div class="col-md-6">
<form class="form-inline" method="get" action="statistics/word_statistics">
<form class="form-inline" method="get" action="word_statistics">
<div class="form-group">
<input type="search" class="form-control" name="word" placeholder="Слово">
</div>
Expand Down

1 comment on commit 4506ec5

@nzinov
Copy link
Contributor Author

@nzinov nzinov commented on 4506ec5 Mar 28, 2014

Choose a reason for hiding this comment

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

Ошибся, он #3 закрывает

Please sign in to comment.