Tuesday, December 7, 2010

Per user tags and recent tags display

TODO: need per-user tags table
that will have uid -> array tag => count
update on every question user posts

===============================

How to find all questions AND answers per user per tag?

If we have tags in answers then it's easy just search for tag $in + $uid
then the same in QUESTIONS

So we really must have tags in ANSWERS!

===================================

Every time a user posts an answer we must also update PER_USER_TAGS collection

=====================================

It would be cool to have PER_USER_VIEWS table

question_id, uid, hts (i_ts not necessary because we can just sort by _id)

Can also collect "interesting tags" based on user views, questions, answers!

======================

Handling "save draft": best is to save draft into USER object under 'q_draft' as array
of title, body, tags

And for answer is a_draft and alo draft_c for comment!

Then after submit answer/question/comment but delete the value from user object

====================================

TODO: when showing "recent tags" Stack does sneaky thing:
it ALWAYS show "YOUR INTERESTING" tags first, even if they are not most recent
and THEN append block with recent tags.

In order to do this we cannot cache recent tags, actually we can for guests
and those who does not yet have "interesting tags"

Then we do 2 selects from RECENT_TAGS: first one with $in => "Interesting tags"
and the second one we get the usual 'recent tags' but remove "my tags" from result
OR specifically in find() pass $not and specify array of "interesting" tags.

It's probably easier to do the usual select, then array_diff
and then append one array to another or merge then so that "MY TAGS" are
always on top!

It actually goes one step beyond this: it also uses per-user tags stats, looks like it
picks some tags from there as well.

So 3 arrays: "My tags", "My stats tags" and "recent tags"
then filters out duplicates and uses them in order of "My tags", "Stat tags", "Recent tags"

Also, how are recent tags updated? Does the new answer trigger update or only new question?
In other words, recent activity for the tag, meaning answer/question/edit/comment (maybe?)
OR just new question?

==========================================

Monday, December 6, 2010

Processing of question

Handling Processing of QForm

Title, body, tags run through utf-8 string first

Run title, tags, body through htmlspecialchars or htmlentities()
or even through string_tags!

In the future if we allow tags then...we will run through safe_html instead!

Make intro
Parse markdown
store [html], [plain]
or just body?

We need something like messageAdapter that will accept
submittedQuestion object

SubmittedQuestion will have:
getBody (UTF8 object is fine, it's even better because we will be able to get num-lines, num-words)
getTitle Utf8String
getTags array
getUser <- UserObject
getIP string

////

tokenize title

record:
PER_USER_TAGS
TITLE_TAGS
QUESTION_TAGS
USER_STATS... not sure what it is but we need to update count_questions of user, right?
Ideally this will be in mongo USER collection
We can have separate collection USER_STATS, it's fine and it's small...


We can also keep reputation there? Maybe but it's really inconvenient because we
need reputation in clsUserObject of oViewer.


Also... we still want similar elist items!

We also want a way to get similar questions (later)
Also need a way to check for duplicate using q_hash uid + body

Need a way to test for floodcheck per uid, per ip

so we need a flood check class that would act as a filter via observer?

It's cool

The similar creation should be done as post-echo call.
also some emailing to subscribers will be done via post-echo thingy

///

Need a way to validate and set form errors.
validate title, validateBody, validateTags

If there are errors in validation we will return the same form.

Otherwise do redirect via meta tag with 2 seconds delay
How to do meta redirect? Basically we need to still show result page
with link to view new question and will say 'you will be redirected in 3 seconds"