Check-in [20553a420c]
Not logged in
Overview

SHA1 Hash:20553a420cb6c453a82924e8edbe11b0f0cbbf40
Date: 2007-12-03 00:27:15
User: drh
Comment:Patch problems with timeline. Need to rethink the whole implementation.
Timelines: ancestors | descendants | both | trunk
Other Links: files | ZIP archive | manifest

Tags And Properties
Changes
[hide diffs]

Modified src/timeline.c from [088a229b70] to [88675c9828].

@@ -119,10 +119,11 @@
     const char *zType = db_column_text(pQuery, 9);
     const char *zUser = db_column_text(pQuery, 4);
     if( cnt==0 && pFirstEvent ){
       *pFirstEvent = rid;
     }
+    cnt++;
     if( pLastEvent ){
       *pLastEvent = rid;
     }
     db_multi_exec("INSERT OR IGNORE INTO seen VALUES(%d)", rid);
     if( xCallback ){
@@ -156,11 +157,20 @@
       }
     }else{
       hyperlink_to_uuid(zUuid);
     }
     db_column_blob(pQuery, 3, &comment);
-    wiki_convert(&comment, 0, WIKI_INLINE);
+    if( blob_size(&comment)>200 ){
+      Blob truncated;
+      blob_zero(&truncated);
+      blob_append(&truncated, blob_buffer(&comment), 200);
+      blob_append(&truncated, "...", 3);
+      wiki_convert(&truncated, 0, WIKI_INLINE);
+      blob_reset(&truncated);
+    }else{
+      wiki_convert(&comment, 0, WIKI_INLINE);
+    }
     blob_reset(&comment);
     @ (by %h(zUser))</td></tr>
   }
   @ </table>
 }
@@ -203,11 +213,11 @@
 const char *timeline_query_for_www(void){
   static const char zBaseSql[] =
     @ SELECT
     @   blob.rid,
     @   uuid,
-    @   datetime(event.mtime,'localtime'),
+    @   datetime(event.mtime,'localtime') AS timestamp,
     @   coalesce(ecomment, comment),
     @   coalesce(euser, user),
     @   (SELECT count(*) FROM plink WHERE pid=blob.rid AND isprim=1),
     @   (SELECT count(*) FROM plink WHERE cid=blob.rid),
     @   NOT EXISTS (SELECT 1 FROM plink WHERE pid=blob.rid),
@@ -229,13 +239,15 @@
 **    e=INTEGER      starting event id.                 dflt: nil
 **    u=NAME         show only events from user.        dflt: nil
 **    a              show events after and including.   dflt: false
 **    r              show only related events.          dflt: false
 **    y=TYPE         show only TYPE ('ci' or 'w')       dflt: nil
+**    s              show the SQL                       dflt: nil
 */
 void page_timeline(void){
   Stmt q;
+  Blob sql;
   char *zSQL;
   Blob scriptInit;
   char zDate[100];
   const char *zStart = P("d");
   int nEntry = atoi(PD("n","20"));
@@ -258,29 +270,31 @@
                 " WHERE login='anonymous'"
                 "   AND cap LIKE '%%h%%'") ){
     @ <p><b>Note:</b> You will be able to access <u>much</u> more
     @ historical information if <a href="%s(g.zTop)/login">login</a>.</p>
   }
-  zSQL = mprintf("%s", timeline_query_for_www());
+  blob_zero(&sql);
+  blob_append(&sql, timeline_query_for_www(), -1);
   if( zType ){
-    zSQL = mprintf("%z AND event.type=%Q", zSQL, zType);
+    blob_appendf(&sql, " AND event.type=%Q", zType);
   }
   if( zUser ){
-    zSQL = mprintf("%z AND event.user=%Q", zSQL, zUser);
+    blob_appendf(&sql, " AND event.user=%Q", zUser);
   }
   if( objid ){
-    char *z = db_text(0, "SELECT datetime(event.mtime) FROM event"
+    char *z = db_text(0, "SELECT datetime(event.mtime, 'localtime') FROM event"
                          " WHERE objid=%d", objid);
     if( z ){
       zStart = z;
     }
   }
   if( zStart ){
     while( isspace(zStart[0]) ){ zStart++; }
     if( zStart[0] ){
-      zSQL = mprintf("%z AND event.mtime %s julianday(%Q, 'localtime')",
-                      zSQL, afterFlag ? ">=" : "<=", zStart);
+      blob_appendf(&sql,
+         " AND event.mtime %s (SELECT julianday(%Q, 'utc'))",
+                          afterFlag ? ">=" : "<=", zStart);
     }
   }
   if( relatedEvents && objid ){
     db_multi_exec(
        "CREATE TEMP TABLE IF NOT EXISTS ok(rid INTEGER PRIMARY KEY)"
@@ -288,21 +302,38 @@
     if( afterFlag ){
       compute_descendents(objid, nEntry);
     }else{
       compute_ancestors(objid, nEntry);
     }
-    zSQL = mprintf("%z AND event.objid IN ok", zSQL);
+    blob_append(&sql, " AND event.objid IN ok", -1);
+  }
+  if( afterFlag ){
+    blob_appendf(&sql, " ORDER BY event.mtime ASC LIMIT %d",
+                 nEntry);
+  }else{
+    blob_appendf(&sql, " ORDER BY event.mtime DESC LIMIT %d",
+                 nEntry);
   }
-  zSQL = mprintf("%z ORDER BY event.mtime DESC LIMIT %d", zSQL, nEntry);
+  zSQL = blob_str(&sql);
+  if( afterFlag ){
+    zSQL = mprintf("SELECT * FROM (%s) ORDER BY timestamp DESC", zSQL);
+  }
   db_prepare(&q, zSQL);
-  free(zSQL);
+  if( P("s")!=0 ){
+    @ <hr><p>%h(zSQL)</p><hr>
+  }
+  blob_zero(&sql);
+  if( afterFlag ){
+    free(zSQL);
+  }
   zDate[0] = 0;
   blob_zero(&scriptInit);
   zDate[0] = 0;
   www_print_timeline(&q, &firstEvent, &lastEvent,
                      save_parentage_javascript, &scriptInit);
   db_finalize(&q);
+  @ <p>firstEvent=%d(firstEvent) lastEvent=%d(lastEvent)</p>
   if( zStart==0 ){
     zStart = zDate;
   }
   @ <script>
   @ var parentof = new Object();
@@ -375,21 +406,22 @@
   @ <input type="text" size="30" value="%h(zStart)" name="d">
   @ Number Of Entries:
   @ <input type="text" size="4" value="%d(nEntry)" name="n">
   @ <br><input type="submit" value="Submit">
   @ </form>
+  @ <table><tr><td>
   @ <form method="GET" action="%s(g.zBaseURL)/timeline">
   @ <input type="hidden" value="%d(lastEvent)" name="e">
   @ <input type="hidden" value="%d(nEntry)" name="n">
   @ <input type="submit" value="Next %d(nEntry) Rows">
-  @ </form>
+  @ </form></td><td>
   @ <form method="GET" action="%s(g.zBaseURL)/timeline">
   @ <input type="hidden" value="%d(firstEvent)" name="e">
-  @ <input type="hidden" value="1" name="a">
   @ <input type="hidden" value="%d(nEntry)" name="n">
+  @ <input type="hidden" value="1" name="a">
   @ <input type="submit" value="Previous %d(nEntry) Rows">
-  @ </form>
+  @ </form></td></tr></table>
   style_footer();
 }
 
 /*
 ** The input query q selects various records.  Print a human-readable