more files

This commit is contained in:
Parziphal 2013-10-26 22:34:21 -05:00
parent 13227f0bca
commit 5f3030c089
11 changed files with 32 additions and 276 deletions

10
.gitignore vendored Executable file
View File

@ -0,0 +1,10 @@
/config/config.php
/config/database.yml
/log/*
/public/assets
/public/data
/tmp/*
/vendor/*
!/vendor/assets
!/vendor/Horde
!/vendor/ZipStream.php

9
composer.json Executable file
View File

@ -0,0 +1,9 @@
{
"name": "myimouto/myimouto",
"require": {
"php": ">=5.4.0",
"myimouto/railsphp": "v1.0.6",
"railsphp/willpaginate": "dev-master",
"michelf/php-markdown": "lib"
}
}

0
log/.gitignore vendored Executable file
View File

3
public/index Executable file
View File

@ -0,0 +1,3 @@
<?php
require __DIR__ . '/../config/boot.php';
MyImouto\Application::dispatchRequest();

View File

@ -1,5 +0,0 @@
<?php
require dirname(__DIR__) . '/config/boot.php';
require dirname(__DIR__) . '/install/ApplicationInstaller/Base.php';
ApplicationInstaller\Base::instance()->dispatch();

View File

@ -1,46 +1,5 @@
<?php
st();
require __DIR__ . '/../config/boot.php';
MyImouto\Application::dispatchRequest();
if (!preg_match('/\.(css|js|json)$/', Rails::application()->dispatcher()->request()->path()) && Rails::application()->dispatcher()->request()->isGet()) {
// st(1);
// echo ' ';
// mu();
}
function st($end = false) {
static $starttime;
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
if (!$end) {
$starttime = $mtime;
} else {
$endtime = $mtime;
$totaltime = ($endtime - $starttime);
echo $totaltime;
}
}
function mu() {
echo 'Memory usage: '.number_to_human_size(memory_get_usage());
}
function number_to_human_size($bytes){
$size = $bytes / 1024;
if($size < 1024){
$size = number_format($size, 1);
$size .= ' KB';
} else {
if($size / 1024 < 1024){
$size = number_format($size / 1024, 1);
$size .= ' MB';
} else if ($size / 1024 / 1024 < 1024) {
$size = number_format($size / 1024 / 1024, 1);
$size .= ' GB';
}
}
return $size;
}
<?php
require dirname(__DIR__) . '/config/boot.php';
require dirname(__DIR__) . '/install/ApplicationInstaller/Base.php';
ApplicationInstaller\Base::instance()->dispatch();

View File

@ -1,66 +0,0 @@
<?php
// echo preg_replace('/^(.*?\d+ .{50}\S+)(.*)?/', '\1', 'abc 234 tag_1 tag_2 tag_3');
// require __DIR__ . '/../config/boot.php';
// $q = Post::where('id < 1000')->limit(10)->take();
// $m = Post::where(['width' => 1000])->where("user_id = ?", 4)->take();
// vpe(Post::find(1));
// vpe($m);
// vpe($q);define('RAILS_ENV', 'development');
require __DIR__ . '/../config/boot.php';
set_time_limit(0);
JobTask::execute_once();
exit;
?>
<!doctype html>
<html><head>
<script src="/assets/application.js"></script>
</head>
<body>
<a href="/dmail/mark_all_read" data-method="post">AAA</a>
<script>
// Comment = Backbone.Model.extend({
// defaults: {
// body: "",
// creator_id: null,
// creator: null,
// post_id: null
// },
// sync: function(method, model, options) {
// if (method == "update")
// options.url = "/comment/update/" + this.get("id") + ".json";
// return Backbone.sync(method, model, options);
// },
// toJSON: function() {
// return {comment:this.attributes}
// },
// urlRoot: function() {
// if (this.isNew()){
// return "/comment";
// } else {
// return "/comment/show.json/";
// }
// }
// })
// Comments = Backbone.Collection.extend({
// model: Comment,
// url: "/comment.json"
// })
// var c, cs;
// cs = new Comments();
// cs.fetch();
// setTimeout(function(){
// c = cs.models[0];
// c.set("body", "hey~~");
// }, 300)
</script>
</body>
</html>

View File

@ -1,101 +0,0 @@
<?php
$dbname = 'myimouto_dev';
$host = '127.0.0.1';
$username = 'root';
$password = 'xamPP';
$total_posts = 200000;
$max_inserts = 5000; # Max inserts at once
set_time_limit(0);
$pdo = new Pdo('mysql:dbname=' . $dbname . ';host=' . $host . ';', $username, $password);
$time = strtotime('20 days ago');
$ratings = ['e', 'q', 'q', 's', 's', 's', 's'];
$max_tags = 20;
$total_queries = ceil($total_posts / $max_inserts);
$post_values = "(
0,
1,
'127.0.0.1',
%d,
'%s',
NULL,
'jpg',
NULL,
NULL,
%d,
%d,
'%s',
'%s',
150,
150,
300,
300,
0,
1,
0,
0,
'active',
0,
0,
NULL,
%d,
%d,
%d,
'%s',
NULL,
NULL,
NULL,
%d,
NULL
)";
$current_id = $pdo->query("SELECT id FROM posts ORDER BY id DESC LIMIT 1")->fetchAll();
if (!$current_id)
$current_id = 0;
else
$current_id = $current_id[0][0];
for ($i = 0; $i < $total_queries; $i++) {
echo "Inserting chunk " . ($i+1) . " of " . $total_queries . "...\n";
$values_clauses = [];
$params = [];
$posts_tags_sql = [];
for ($c = 0; $c < $max_inserts; $c++) {
$filesize = rand(2000, 3000);
$md5 = md5($time);
$width = rand(1500, 2000);
$height = rand(1500, 2000);
$created_at = date('Y-m-d H:i:s', $time);
$rating = $ratings[array_rand($ratings)];
$sample_width = rand(500, 1500);
$sample_height = rand(500, 1500);
$sample_size = rand(1000, 2000);
$index_timestamp = $created_at;
$random = rand(100, 9999999999);
$values_clauses[] = sprintf($post_values, $filesize, $md5, $width, $height, $created_at, $rating, $sample_width, $sample_height, $sample_size, $index_timestamp, $random);
$post_id = $pdo->lastInsertId();
$tag_count = rand(1, $max_tags);
$current_id++;
foreach (range(1, $tag_count) as $ii) {
$posts_tags_sql[] = '(' . $current_id . ', ' . rand(1, 32000) . ')';
}
$time++;
}
$sql = "INSERT INTO posts VALUES ";
$sql .= implode(', ', $values_clauses);
$pdo->query($sql);
$sql = "INSERT INTO posts_tags VALUES " . implode(', ', $posts_tags_sql);
$pdo->query($sql);
}
echo "Done inserting " . $total_posts . " rows.\n";

View File

@ -1,59 +0,0 @@
<?php
require dirname(__FILE__) . '/../boot.php';
if (!Moebooru::application()->validate_safe_ips()) {
require 'under_maintenance.html';
exit;
}
set_time_limit(0);
# Change collation
ActiveRecord::connection()->exec("ALTER TABLE `tags` CHANGE `name` `name` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL");
# Non-utf8 connection.
$db_data = Rails::application()->config('activerecord');
$db_data['connection'] = trim(str_replace('charset=utf8', '', $db_data['connection']), ';');
ActiveRecord::add_connection($db_data, 'nonutf8');
$min = 1;
$max = 1000;
$tags = Tag::find_all(['conditions' => "id > $min AND id < $max"]);
while ($tags->any()) {
ActiveRecord::set_connection('nonutf8');
foreach ($tags as $tag) {
$decoded = utf8_decode($tag->name);
if (!preg_match('!!u', $decoded)) {
try {
$t = Tag::find($tag->id);
ActiveRecord::set_connection('default');
ActiveRecord::connection()->beginTransaction();
$tag->update_attributes(['name' => $t->name, 'cached_related' => '', 'cached_related_expires_on' => null]);
} catch (Exception $e) {
$error = '<h3>Error</h3>';
$error .= '<p>Type: ' .get_class($e). '</p>';
$error .= '<p>Message: '.$e->getMessage().'</p>';
$error .= '<p>Tag id: '.$t->id.'</p>';
$error .= '<p>UTF8 name: '.$tag->name.'</p>';
$error .= '<p>Non-UTF8 name: '.$t->name.'</p>';
$error .= '<hr />';
echo $error;
ActiveRecord::connection()->rollBack();
continue;
}
ActiveRecord::connection()->commit();
}
}
$min += 1000;
$max += 1000;
$tags = Tag::find_all(['conditions' => "id > $min AND id < $max"]);
}
unlink(Rails::root() . '/public/under_maintenance.html');
unlink(Rails::root() . '/public/index.php');
rename(Rails::root() . '/public/index', Rails::root() . '/public/index.php');
header('Location: /');

View File

@ -0,0 +1,6 @@
<?php
define('RAILS_ENV', 'development');
require dirname(__DIR__) . '/../config/boot.php';
set_time_limit(0);
JobTask::execute_once();

0
tmp/.gitignore vendored Executable file
View File