Skip to content

Commit

Permalink
Merge pull request #1440 from Scifabric/fix-cache-project-user
Browse files Browse the repository at this point in the history
Fix cache project user
  • Loading branch information
teleyinex authored Jan 31, 2017
2 parents 267b9d2 + 21a5ad5 commit c40bbc0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pybossa/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ def warm_cache(): # pragma: no cover
import pybossa.cache.users as cached_users
import pybossa.cache.project_stats as stats
from pybossa.util import rank
from pybossa.core import user_repo

def warm_project(_id, short_name, featured=False):
if _id not in projects_cached:
Expand Down Expand Up @@ -393,10 +394,12 @@ def warm_project(_id, short_name, featured=False):
users = cached_users.get_leaderboard(app.config['LEADERBOARD'])
for user in users:
# print "Getting stats for %s" % user['name']
print user_repo
u = user_repo.get_by_name(user['name'])
cached_users.get_user_summary(user['name'])
cached_users.projects_contributed_cached(user['id'])
cached_users.published_projects_cached(user['id'])
cached_users.draft_projects_cached(user['id'])
cached_users.projects_contributed_cached(u.id)
cached_users.published_projects_cached(u.id)
cached_users.draft_projects_cached(u.id)

return True

Expand Down
13 changes: 13 additions & 0 deletions test/test_jobs/test_project_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
# along with PYBOSSA. If not, see <http://www.gnu.org/licenses/>.

from pybossa.jobs import get_project_jobs, create_dict_jobs, get_project_stats
from pybossa.jobs import warm_cache
from default import Test, with_context
from factories import ProjectFactory
from factories import UserFactory
from factories import TaskRunFactory
from factories import TaskFactory


class TestProjectsStats(Test):
Expand Down Expand Up @@ -79,3 +82,13 @@ def test_get_project_jobs_for_non_pro_users(self):

err_msg = "There should be only 0 jobs"
assert len(jobs) == 0, err_msg

@with_context
def test_warm_project(self):
"""Test JOB warm_project works."""
project = ProjectFactory.create()
task = TaskFactory.create(n_answers=1)
for i in range(0,30):
TaskRunFactory.create(project=project, task=task)
res = warm_cache()
assert res, res

0 comments on commit c40bbc0

Please sign in to comment.