2 # The contents of this file are subject to the Common Public Attribution
3 # License Version 1.0. (the "License"); you may not use this file except in
4 # compliance with the License. You may obtain a copy of the License at
5 # http://code.reddit.com/LICENSE. The License is based on the Mozilla Public
6 # License Version 1.1, but Sections 14 and 15 have been added to cover use of
7 # software over a computer network and provide for limited attribution for the
8 # Original Developer. In addition, Exhibit A has been modified to be consistent
11 # Software distributed under the License is distributed on an "AS IS" basis,
12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
13 # the specific language governing rights and limitations under the License.
15 # The Original Code is reddit.
17 # The Original Developer is the Initial Developer. The Initial Developer of
18 # the Original Code is reddit Inc.
20 # All portions of the code written by reddit are Copyright (c) 2006-2015 reddit
21 # Inc. All Rights Reserved.
22 ###############################################################################
26 # expects two environment variables
27 # REDDIT_ROOT = path to the root of the reddit public code; the directory with the Makefile
28 # REDDIT_INI = path to the ini file to use
29 # which should be supplied via:
30 source /etc
/default
/reddit
31 # additionally, some configuration can be overridden in the environment
32 export TMPDIR
=${TMPDIR:-/tmp}
33 export PGUSER
=${PGUSER:-reddit}
34 export PGHOST
=${PGHOST:-localhost}
37 # one of "link" or "comment"
39 # period of data to extract from postgres: e.g. "hour", "week", "year", "all"
41 # which period listings to update.
42 # formatted as python tuple of strings: e.g. '("hour",)' or ("week", "all",) etc
45 echo "Starting $THING_CLS processing"
47 THING_DUMP
=$TMPDIR/$THING_CLS-$INTERVAL-thing.dump
48 DATA_DUMP
=$TMPDIR/$THING_CLS-$INTERVAL-data.dump
50 rm -f $THING_DUMP $DATA_DUMP
54 if [ -e $THING_DUMP ]; then
55 echo cannot start because
$THING_DUMP exists
63 psql
-F"\t" -A -t -c "$1"
71 paster
--plugin=r2 run
$REDDIT_INI $REDDIT_ROOT/r
2/lib
/mr_top.py
-c "$1"
74 # Hack to let pg fetch all things with intervals
75 if [ $INTERVAL = "all" ]; then
76 export INTERVAL
="century"
79 MINID
=$
(run_query
"SELECT thing_id
80 FROM reddit_thing_$THING_CLS
82 date > now() - interval '1 $INTERVAL' AND
86 if [ -z $MINID ]; then
87 echo \
$MINID is empty. Replication is likely behind.
91 run_query
"\\copy (SELECT thing_id, 'thing', '$THING_CLS', ups, downs, deleted, spam, extract(epoch from date)
92 FROM reddit_thing_$THING_CLS
98 run_query
"\\copy (SELECT thing_id, 'data', '$THING_CLS', key, value
99 FROM reddit_data_$THING_CLS
101 key IN ('url', 'sr_id', 'author_id') AND
105 cat $THING_DUMP $DATA_DUMP |
107 reddit
"join_things('$THING_CLS')" |
108 reddit
"time_listings($TIMES, '$THING_CLS')" |
110 reddit
"write_permacache()"