Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[livejournal] r16070: LJSV-13:

Committer: ailyin
LJSV-13:

- include "still attending" people to the search results for a
particular year

- allow passing "now" as year value for filtering

U   trunk/cgi-bin/schoollib.pl
U   trunk/htdocs/schools/index.bml
Modified: trunk/cgi-bin/schoollib.pl
===================================================================
--- trunk/cgi-bin/schoollib.pl	2009-12-23 06:18:48 UTC (rev 16069)
+++ trunk/cgi-bin/schoollib.pl	2009-12-23 07:21:10 UTC (rev 16070)
@@ -119,8 +119,32 @@
 # returns: List of userids that attended.
 # </LJFUNC>
 sub get_attendees {
+
+    # working with the years logic is a little bit hacky in this sub. we assume
+    # that everyone will graduate from their school by the year 3000 -- this
+    # way, "1999 - still attending" type of school will definitely come up in
+    # searches for "attended in 2000", because 1999 < 2000 < 3000.
+    # as for the "year" param of this prop, it allows for passing "now", which
+    # gets casted to 2999 -- and it only matches people who are still attending
+    # the school (that is, will graduate in 3000 ;-))
+    #
+    # I know that it is a sub-optimal way from the engineering standpoint,
+    # but this allowed me to limit SQL to just one query, and that query
+    # is quite efficient. (I considered doing ORs or UNIONs, and the solution
+    # here seems better to me.)
+    #
+    # NOTE: this will only work for about a thousand years; I think it's
+    # good enough for now. ;-)
+
     my $sid = shift() + 0;
-    my $year = shift() + 0;
+
+    my $year = shift;
+    if ($year eq 'now') {
+        $year = 2999;
+    } else {
+        $year = $year + 0;
+    }
+
     return undef unless $sid;
 
     # see if it's in memcache first
@@ -141,7 +165,7 @@
                 SELECT userid
                 FROM schools_attended
                 WHERE schoolid = ?
-                  AND ? BETWEEN year_start AND year_end
+                  AND ? BETWEEN year_start AND COALESCE(year_end, 3000)
                 LIMIT 1000
             }, undef, $sid, $year);
     } else {

Modified: trunk/htdocs/schools/index.bml
===================================================================
--- trunk/htdocs/schools/index.bml	2009-12-23 06:18:48 UTC (rev 16069)
+++ trunk/htdocs/schools/index.bml	2009-12-23 07:21:10 UTC (rev 16070)
@@ -506,11 +506,8 @@
     my $year = $GET{'year'} || 0;
     $year += 1900 if $year =~ /^\d{2}$/;
     return $err->($ML{'.error.invalidyear'})
-        if $year && $year !~ /^\d{4}$/;
+        if $year && $year !~ /^\d{4}$/ && $year ne 'now';
 
-    $year += 0;
-    $year = 0 if $year < 1900;
-
     my @ids = LJ::Schools::get_attendees($sid, $year);
 
     # now multi-load and split

Tags: andy, bml, livejournal, pl
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments