First time here? Check out the FAQ!
0

seeding vote count for questions

In the process of rewriting the importer for Zendesk, I'm wondering if there's a generic way to seed the vote count for a particular question. I found the increase_view_count() method for increasing the view count but couldn't find a similar method for increasing the vote count as it seems they have to be specifically linked to the users who submitted the vote.

The Zendesk XML export used to import data doesn't have any specific information regarding who voted for a forum topic, it only has the overall vote count.

Is there a way to do this easily?

kporangehat's avatar
1
kporangehat
asked 2013-06-11 15:45:14 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

1

Maybe you could create a special user account and make it vote? There may be a limitation on the number of votes per day - if you hit that we might need to do something about this.

If you don't like to display that account in the future - just make it "blocked" - blocked accounts don't show anywhere.

To avoid hitting limitations of votes per post and votes per user per day - create a function in the importer vote() or something like that.

On post - save points, vote_up_count, vote_down_count - denormalized values. You might get away with just maintaining these, but for the better DB consistency I would for each vote also create a vote object: Vote(user = user, voted_post=post, vote=Vote.VOTE_UP, voted_at=timestamp).save().

Since the account will be throwaway - don't worry about tracking users karma.

Evgeny's avatar
13.2k
Evgeny
answered 2013-06-11 15:47:39 -0500, updated 2013-06-11 16:21:05 -0500
edit flag offensive 0 remove flag delete link

Comments

Can't a user only vote up a question once?

kporangehat's avatar kporangehat (2013-06-11 16:06:42 -0500) edit

Yes, you're right! I'll see what else I can suggest.

Evgeny's avatar Evgeny (2013-06-11 16:08:13 -0500) edit

Brilliant. I think that will work. I'll give it a shot. Thanks!

kporangehat's avatar kporangehat (2013-06-11 16:19:25 -0500) edit

Couple of issues: 1) When I run post.points = n, post.save(), the question list doesn't show the votes. However if I click into the Question, the votes are displayed and then the next time I go to the question list, I see the votes listed. Even setting the post.vote_up_count = n as well doesn't display the vote count in the question list. 2) Once I have clicked into the question and navigate back to the question list, the sorting by vote count doesn't seem to work.

I can probably figure this all out, but can you explain the relationship between Vote, and Post.points/vote_up_count/vote_down_count?

kporangehat's avatar kporangehat (2013-06-12 12:12:42 -0500) edit

It's because of the cache. Just delete all cache after the import:

python manage.py shell
from django.core.cache import cache
cache.clear()

There is cache for the question summary snippet for the front page.

Evgeny's avatar Evgeny (2013-06-12 12:16:50 -0500) edit
add a comment see more comments