cd `dirname $0`
cd ../dstore

STARTTIME=$(date +%s)
echo "Starting Import of all xml files at $(date)" | tee -a cache/time.log

# remove old logs
truncate -s 0 cache/*.import.last.log

#import all xml files

doimport() {

file=$1

echo | tee -a ${file}.import.log ${file}.import.last.log
date | tee -a ${file}.import.log ${file}.import.last.log
echo | tee -a ${file}.import.log ${file}.import.last.log

echo "Importing $file" | tee -a ${file}.import.log ${file}.import.last.log

./dstore import $file 2>&1 | tee -a ${file}.import.log ${file}.import.last.log


echo | tee -a ${file}.import.log ${file}.import.last.log
}
export -f doimport
ls cache/*.xml -S | parallel --jobs 50% --bar doimport

echo "Adding fake transactions at $(date)" | tee -a cache/time.log
./dstore fake

echo "Augmenting related table at $(date)" | tee -a cache/time.log
./dstore augment

echo "Starting Analyze of database at $(date)" | tee -a cache/time.log
./dstore analyze


ENDTIME=$(date +%s)
echo "Finished Import of all xml files at $(date)" | tee -a cache/time.log
echo "Import took  $(($ENDTIME - $STARTTIME)) seconds to complete." | tee -a cache/time.log
echo "" | tee -a cache/time.log

