-
Notifications
You must be signed in to change notification settings - Fork 1
/
load.go
124 lines (100 loc) · 2.44 KB
/
load.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"runtime"
)
var _ = runtime.GC
func loadLocations(filename string) {
log.Println("loadLocations", filename)
file, e := os.Open(filename)
if e != nil {
fmt.Printf("File error: %v\n", e)
os.Exit(1)
}
defer file.Close()
dec := json.NewDecoder(file)
// skip '{', 'locations', '['
_,_ = dec.Token()
_,_ = dec.Token()
_,_ = dec.Token()
var l location_update
for {
dec.Decode(&l)
loadLocation(*l.Id, &l)
locationsCount++
if !dec.More() {
return
}
}
}
func loadUsers(filename string) {
log.Println("loadUsers", filename)
file, e := os.Open(filename)
if e != nil {
fmt.Printf("File error: %v\n", e)
os.Exit(1)
}
defer file.Close()
dec := json.NewDecoder(file)
// skip '{', 'users', '['
_,_ = dec.Token()
_,_ = dec.Token()
_,_ = dec.Token()
var u user_update
for {
dec.Decode(&u)
loadUser(*u.Id, &u)
usersCount++
if !dec.More() {
return
}
}
}
func loadVisits(filename string) {
log.Println("loadVisits", filename)
file, e := os.Open(filename)
if e != nil {
fmt.Printf("File error: %v\n", e)
os.Exit(1)
}
defer file.Close()
dec := json.NewDecoder(file)
// skip '{', 'visits', '['
_,_ = dec.Token()
_,_ = dec.Token()
_,_ = dec.Token()
var v visit_update
for {
dec.Decode(&v)
loadVisit(*v.Id, &v)
visitsCount++
if !dec.More() {
return
}
}
}
func loadAll(root string) {
files, err := ioutil.ReadDir(root)
if err != nil {
log.Fatal(err)
}
for _, file := range files {
if file.Name()[0] == 108 { // ord('l') = 108 = locations
loadLocations(root + "/" + file.Name())
}
if file.Name()[0] == 117 { // ord('u') = 117 = users
loadUsers(root + "/" + file.Name())
}
if file.Name()[0] == 118 { // ord('v') = 118 = visits
loadVisits(root + "/" + file.Name())
}
}
//runtime.GC()
log.Printf("Locations: %d + %d = %d", locationsMaxCount, len(locations), locationsCount)
log.Printf("Users: %d + %d = %d", usersMaxCount, len(users), usersCount)
log.Printf("Visits: %d + %d = %d", visitsMaxCount, len(visits), visitsCount)
}