Fix an index related bug in the patcher.

Fix AS in columns in left joins.
Remove a redundant AS in simple count.
Remove a couple of unused session parameters.
Shorten a few session bits.
This commit is contained in:
Azareal 2019-07-29 11:31:19 +10:00
parent 377a5dc5ea
commit ef4a88c43f
4 changed files with 29 additions and 18 deletions

View File

@ -216,7 +216,7 @@ func (a *MysqlAdapter) AddIndex(name string, table string, iname string, colname
return "", errors.New("You need a name for the column")
}
querystr := "ALTER TABLE `" + table + "` ADD INDEX " + "`" + iname + "` (`" + colname + "`);"
querystr := "ALTER TABLE `" + table + "` ADD INDEX " + "`i_" + iname + "` (`" + colname + "`);"
// TODO: Shunt the table name logic and associated stmt list up to the a higher layer to reduce the amount of unnecessary overhead in the builder / accumulator
a.pushStatement(name, "add-index", querystr)
return querystr, nil
@ -673,7 +673,18 @@ func (adapter *MysqlAdapter) SimpleLeftJoin(name string, table1 string, table2 s
return "", err
}
var querystr = "SELECT" + adapter.buildJoinColumns(columns) + " FROM `" + table1 + "` LEFT JOIN `" + table2 + "` ON " + adapter.buildJoiners(joiners) + whereStr + adapter.buildOrderby(orderby) + adapter.buildLimit(limit)
thalf1 := strings.Split(strings.Replace(table1," as ", " AS ",-1)," AS ")
var as1 string
if len(thalf1) == 2 {
as1 = " AS `"+ thalf1[1]+"`"
}
thalf2 := strings.Split(strings.Replace(table2," as ", " AS ",-1)," AS ")
var as2 string
if len(thalf2) == 2 {
as2 = " AS `"+ thalf2[1]+"`"
}
var querystr = "SELECT" + adapter.buildJoinColumns(columns) + " FROM `" + thalf1[0] + "`"+as1+" LEFT JOIN `" + thalf2[0] + "`"+as2+" ON " + adapter.buildJoiners(joiners) + whereStr + adapter.buildOrderby(orderby) + adapter.buildLimit(limit)
querystr = strings.TrimSpace(querystr)
adapter.pushStatement(name, "select", querystr)
@ -808,7 +819,7 @@ func (adapter *MysqlAdapter) buildLimit(limit string) (q string) {
return q
}
func (adapter *MysqlAdapter) buildJoinColumns(columns string) (q string) {
func (a *MysqlAdapter) buildJoinColumns(columns string) (q string) {
for _, column := range processColumns(columns) {
// TODO: Move the stirng and number logic to processColumns?
// TODO: Error if [0] doesn't exist
@ -861,7 +872,7 @@ func (adapter *MysqlAdapter) SimpleCount(name string, table string, where string
return "", err
}
q = "SELECT COUNT(*) AS `count` FROM `" + table + "`" + whereStr + adapter.buildLimit(limit)
q = "SELECT COUNT(*) FROM `" + table + "`" + whereStr + adapter.buildLimit(limit)
q = strings.TrimSpace(q)
adapter.pushStatement(name, "select", q)
return q, nil

View File

@ -1,11 +1,11 @@
ALTER TABLE `topics` ADD INDEX `parentID` (`parentID`);;
ALTER TABLE `replies` ADD INDEX `tid` (`tid`);;
ALTER TABLE `polls` ADD INDEX `parentID` (`parentID`);;
ALTER TABLE `likes` ADD INDEX `targetItem` (`targetItem`);;
ALTER TABLE `emails` ADD INDEX `uid` (`uid`);;
ALTER TABLE `attachments` ADD INDEX `originID` (`originID`);;
ALTER TABLE `attachments` ADD INDEX `path` (`path`);;
ALTER TABLE `activity_stream_matches` ADD INDEX `watcher` (`watcher`);;
ALTER TABLE `topics` ADD INDEX `i_parentID` (`parentID`);;
ALTER TABLE `replies` ADD INDEX `i_tid` (`tid`);;
ALTER TABLE `polls` ADD INDEX `i_parentID` (`parentID`);;
ALTER TABLE `likes` ADD INDEX `i_targetItem` (`targetItem`);;
ALTER TABLE `emails` ADD INDEX `i_uid` (`uid`);;
ALTER TABLE `attachments` ADD INDEX `i_originID` (`originID`);;
ALTER TABLE `attachments` ADD INDEX `i_path` (`path`);;
ALTER TABLE `activity_stream_matches` ADD INDEX `i_watcher` (`watcher`);;
INSERT INTO `sync`(`last_update`) VALUES (UTC_TIMESTAMP());
INSERT INTO `settings`(`name`,`content`,`type`,`constraints`) VALUES ('activation_type','1','list','1-3');
INSERT INTO `settings`(`name`,`content`,`type`) VALUES ('bigpost_min_words','250','int');

View File

@ -4,15 +4,15 @@
<div id="panel_users" class="colstack_item rowlist bgavatars">
{{range .ItemList}}
<div class="rowitem" style="background-image:url('{{.Avatar}}');">
<a class="rowAvatar"{{if $.CurrentUser.Perms.EditUser}} href="/panel/users/edit/{{.ID}}?s={{$.CurrentUser.Session}}"{{end}}>
<a class="rowAvatar"{{if $.CurrentUser.Perms.EditUser}} href="/panel/users/edit/{{.ID}}"{{end}}>
<img class="bgsub" src="{{.Avatar}}" alt="Avatar" aria-hidden="true" />
</a>
<a class="rowTitle"{{if $.CurrentUser.Perms.EditUser}} href="/panel/users/edit/{{.ID}}?s={{$.CurrentUser.Session}}"{{end}}>{{.Name}}</a>
<a class="rowTitle"{{if $.CurrentUser.Perms.EditUser}} href="/panel/users/edit/{{.ID}}"{{end}}>{{.Name}}</a>
<span class="panel_floater">
<a href="{{.Link}}" class="tag-mini profile_url">{{lang "panel_users_profile"}}</a>
{{if (.Tag) and (.IsSuperMod)}}<span class="panel_tag">{{.Tag}}</span></span>{{end}}
{{if .IsBanned}}<a href="/users/unban/{{.ID}}?session={{$.CurrentUser.Session}}" class="panel_tag panel_right_button ban_button">{{lang "panel_users_unban"}}</a>{{else if not .IsSuperMod}}<a href="/user/{{.ID}}#ban_user" class="panel_tag panel_right_button ban_button">{{lang "panel_users_ban"}}</a>{{end}}
{{if not .Active}}<a href="/users/activate/{{.ID}}?session={{$.CurrentUser.Session}}" class="panel_tag panel_right_button">{{lang "panel_users_activate"}}</a>{{end}}
{{if .IsBanned}}<a href="/users/unban/{{.ID}}?s={{$.CurrentUser.Session}}" class="panel_tag panel_right_button ban_button">{{lang "panel_users_unban"}}</a>{{else if not .IsSuperMod}}<a href="/user/{{.ID}}#ban_user" class="panel_tag panel_right_button ban_button">{{lang "panel_users_ban"}}</a>{{end}}
{{if not .Active}}<a href="/users/activate/{{.ID}}?s={{$.CurrentUser.Session}}" class="panel_tag panel_right_button">{{lang "panel_users_activate"}}</a>{{end}}
</span>
</div>
{{end}}

View File

@ -34,11 +34,11 @@
<a class="profile_menu_item">{{lang "profile_add_friend"}}</a>
</div>-->
{{if (.CurrentUser.IsSuperMod) and not (.ProfileOwner.IsSuperMod) }}<div class="rowitem passive">
{{if .ProfileOwner.IsBanned }}<a href="/users/unban/{{.ProfileOwner.ID}}?session={{.CurrentUser.Session}}" class="profile_menu_item">{{lang "profile_unban"}}</a>
{{if .ProfileOwner.IsBanned}}<a href="/users/unban/{{.ProfileOwner.ID}}?s={{.CurrentUser.Session}}" class="profile_menu_item">{{lang "profile_unban"}}</a>
{{else}}<a href="#ban_user" class="profile_menu_item">{{lang "profile_ban"}}</a>{{end}}
</div>{{end}}
<div class="rowitem passive">
<a href="/report/submit/{{.ProfileOwner.ID}}?session={{.CurrentUser.Session}}&type=user" class="profile_menu_item report_item" aria-label="{{lang "profile_report_user_aria"}}" title="{{lang "profile_report_user_tooltip"}}"></a>
<a href="/report/submit/{{.ProfileOwner.ID}}?s={{.CurrentUser.Session}}&type=user" class="profile_menu_item report_item" aria-label="{{lang "profile_report_user_aria"}}" title="{{lang "profile_report_user_tooltip"}}"></a>
</div>
{{end}}
</div>